// Arup Guha
// Solution to 9/14/2013 UCF JV Practice Problem: Lattice
// 9/13/2013

import java.util.*;

public class lattice {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=0; loop<numCases; loop++) {

			// Will accumulate our answer.
			long ans = 0L;

			// Origin.
			long[] cur = new long[2];
			int n = stdin.nextInt();

			// Traverse each side, adding up lattice points.
			for (int i=0; i<n-1; i++) {
				long[] next = new long[2];
				next[0] = stdin.nextLong();
				next[1] = stdin.nextLong();
				ans += numLatticePts(cur, next);
				cur = next;
			}

			// Need to add the last side in manually.
			ans += numLatticePts(cur, new long[2]);

			// Output result.
			System.out.println(ans);
		}
	}

	public static long numLatticePts(long[] a, long[] b) {
		return gcd(Math.abs(a[0]-b[0]), Math.abs(a[1]-b[1]));
	}

	public static long gcd(long x, long y){
		if (y == 0) return x;
		return gcd(y, x%y);
	}
}