// Patrick Fenelon
// 7/121/2011
// Solution for BHCSI 2011 Practice Contest #2 Problem: Conference

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class conference {


	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(new File("conference.in"));
		new conference(sc);		
	}
	
	// This constructor does all the work, reading in each case, 
	// solving and outputting the results.
	public conference(Scanner sc) {
		
		// Go through each test case.
		int t = sc.nextInt();		
		for(int c = 0; c < t; c++){
			
			int n = sc.nextInt();
			// array stores the length in days of a conference starting on the index value
			// i.e. array[3] = 5; means a conference starting on day 3 lasts 5 days
			//      array[4] = 0; means no conference offer starts on day 4
			int[] offers = new int[30]; 
			
			//step through input
			for(int i = 0; i < n; i++){
				int startDay = sc.nextInt();
				int length = sc.nextInt();
				offers[startDay] = length;
			}
			
			//represents if conference is booked on a given day
			boolean[] conferenceBooked = new boolean[30];
			
			//step through offers
			for(int i = 0; i < 30; i++){
				//if we aren't already booked
				if(!conferenceBooked[i]){
					//book us for the next conference
					for(int j = i; j < i + offers[i]; j++){
						conferenceBooked[j] = true;
					}
				}
			}
			
			
			//profit is the problem answer
			int profit = 0;
			//go total up the profit
			for(int i = 0; i < 30; i++){
				//profit on day i is 2^(29-i)
				if(conferenceBooked[i]){
					int priceOnDay = (int)Math.pow(2, 29-i);
					profit += priceOnDay;
				}
			}
			
			System.out.println(profit);
				
		}
	}

}
