// Arup Guha
// 2/26/2020
// Solution to COP 4516 Individual Final Contest Problem C: Out of Town

import java.util.*;

public class clarge {

	// Given in the problem.
	final public static int TOTAL = 121;

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Do all cases here.
		for (int loop=0; loop<nC; loop++) {
		
			// Get the number of vacations.
			int numVacations = stdin.nextInt();
			
			// At first, Arup's here all the time!
			int res = TOTAL;
			
			// Sub out the vacations.
			for (int i=0; i<numVacations; i++) {
			
				// The month doesn't even matter!
				String junk = stdin.next();
				
				// Number of days in the range is always end-start+1.
				int start = stdin.nextInt();
				int end = stdin.nextInt();
				res -= (end-start+1);
			}
			
			// Ta da!
			System.out.println(res);
		}
	}
}