1. JAVA, Till Fischer

/*
 ============================================================================
 Name            : Main.java
 Author            : Till Fischer
 Description    : 10013 - Super long sums
 Accepted        : TLE
 Time            : > 3.000
 ============================================================================
 */

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int cases, places;
        byte temp;
        byte[] a,b;
        String[] splitted;
        a = new byte[1000000];
        b = new byte[1000000];
        
        for(cases = Integer.parseInt(reader.readLine()); cases > 0; cases--) {
            //one empty line
            reader.readLine();
            places = Integer.parseInt(reader.readLine());
            a[places] = 0;
            places--;
            for(; places >= 0; places--) {
                splitted = reader.readLine().split(" ");
                a[places] = Byte.parseByte(splitted[0]);
                b[places] = Byte.parseByte(splitted[1]);
            }
            for(places = 0; places < a.length - 1; places++) {
                temp = (byte) (a[places] + b[places]);
                if(temp >= 10) {
                    a[places+1] += 1;
                }
                a[places] = (byte) (temp % 10);
            }
            
            if(!(a[a.length - 1] == 0)) {
                writer.append((new Integer(a[a.length-1]).toString()));
            }
            for(places = a.length - 2; places >= 0; places--) {
                writer.append((char) (a[places] + '0'));
            }
            writer.append("\n");
            if(!(cases == 1))
                writer.append("\n");
        }
        //always be nice to streams!
        reader.close();
        writer.flush();
        writer.close();
    }
    
/*// BigInteger version
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        int cases, places;
        String[] splitted;
        StringBuilder a,b;
        for(cases = Integer.parseInt(reader.readLine()); cases > 0; cases--) {
            //one empty line
            reader.readLine();
            a = new StringBuilder();
            b = new StringBuilder();
            for(places = Integer.parseInt(reader.readLine()); places > 0; places--) {
                splitted = reader.readLine().split(" ");
                a.append(splitted[0]);
                b.append(splitted[1]);
            }
            writer.append(new BigInteger(a.toString()).add(new BigInteger(b.toString())).toString());
            if(!(cases == 1))
                writer.append("\n");
        }
        //always be nice to streams!
        reader.close();
        writer.flush();
        writer.close();
    }
    */
}