Polycarp found n segments on the street. A segment with the index i is described by two integers l_i and r_i — coordinates of the beginning and end of the segment, respectively. Polycarp realized that he didn't need all the segments, so he wanted to delete some of them.

Polycarp believes that a set of k segments is good if there is a segment [l_i, r_i] (1 ≤ i ≤ k) from the set, such that it intersects every segment from the set (the intersection must be a point or segment). For example, a set of 3 segments [[1, 4], [2, 3], [3, 6]] is good, since the segment [2, 3] intersects each segment from the set. Set of 4 segments [[1, 2], [2, 3], [3, 5], [4, 5]] is not good.

Polycarp wonders, what is the minimum number of segments he has to delete so that the remaining segments form a good set?

Input

The first line contains a single integer t (1 ≤ t ≤ 2 ⋅ 10^5) — number of test cases. Then t test cases follow.

The first line of each test case contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of segments. This is followed by n lines describing the segments.

Each segment is described by two integers l and r (1 ≤ l ≤ r ≤ 10^9) — coordinates of the beginning and end of the segment, respectively.

It is guaranteed that the sum of n for all test cases does not exceed 2 ⋅ 10^5.

Output

For each test case, output a single integer — the minimum number of segments that need to be deleted in order for the set of remaining segments to become good.

Example

Input


4
3
1 4
2 3
3 6
4
1 2
2 3
3 5
4 5
5
1 2
3 8
4 5
6 7
9 10
5
1 5
2 4
3 5
3 8
4 8


Output


0
1
2
0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

/* ------------ Theorems and Lemmas ------------ */

// Fermat's Little Theorem
// (1) ((a ** p) - a) % p = 0; if 'p' is prime
// (2) Further, if 'a % p != 0', then ((a ** (p - 1)) - 1) % p = 0

/* -------------- End of theorems -------------- */

public class Solution {

	// Digit DP
	private static int digit;
	private static int times;
	private static StringBuilder number;
	private static int[][][] digitDP;
	// End

	public static void main(String[] args) {
		FastReader reader = new FastReader();
		int t = reader.nextInt();
		while (t-- > 0) {
			int n = reader.nextInt();
			// (1) Co-ordinate compress
			Seg[] segs = new Seg[n];
			for (int i = 0; i < n; ++i)
				segs[i] = new Seg(reader.nextInt(), reader.nextInt());
			Set<Integer> set = new TreeSet<>();
			for (Seg s : segs) {
				set.add(s.l);
				set.add(s.r);
			}
			Map<Integer, Integer> map = new HashMap<>();
			for (int i : set)
				map.put(i, map.size());
			for (Seg s : segs) {
				s.l = map.get(s.l);
				s.r = map.get(s.r);
			}
			// (2) Create event for start and end of each line segment
			Event[] events = new Event[2 * n];
			int ind = 0;
			for (Seg s : segs) {
				events[ind++] = new Event(s.l, s.r, true);
				events[ind++] = new Event(s.l, s.r, false);
			}
			Arrays.sort(events, (e1, e2) -> {
				if (e1.start) {
					if (e2.start)
						return e1.x1 != e2.x1 ? e1.x1 - e2.x1 : 0;
					else
						return e1.x1 > e2.x2 ? 1 : -1;
				} else {
					if (e2.start)
						return e1.x2 < e2.x1 ? -1 : 1;
					else
						return e1.x2 - e2.x2;
				}
			});
			// (3) Apply Fenwick Tree (BIT) to get the group with max segments
			BIT bit = new BIT(map.size() + 1);
			int ans = 0;
			for (Event e : events) {
				if (e.start)
					bit.update(e.x2, 1);
				else
					ans = Math.max(ans, bit.query(e.x1, map.size()));
			}
			// (4) Print n - max
			System.out.println(n - ans);
		}
		reader.close();
	}

	static class Seg {
		int l;
		int r;

		public Seg(int l, int r) {
			this.l = l;
			this.r = r;
		}
	}

	static class Event {
		int x1;
		int x2;
		boolean start;

		public Event(int x1, int x2, boolean start) {
			this.x1 = x1;
			this.x2 = x2;
			this.start = start;
		}
	}

	static class BIT {
		int n;
		int[] tree;

		public BIT(int n) {
			this.n = n;
			tree = new int[n + 1];
		}

		void update(int i, int val) {
			for (i++; i <= n; i += i & -i)
				tree[i] += val;
		}

		int read(int i) {
			int sum = 0;
			for (i++; i > 0; i -= i & -i)
				sum += tree[i];
			return sum;
		}

		// query sum of [l, r] inclusive
		int query(int l, int r) {
			return read(r) - read(l - 1);
		}

		// if the BIT is a freq array, returns the index of the
		// kth item (0-indexed), or n if there are <= k items.
		int getKth(int k) {
			if (k < 0)
				return -1;
			int i = 0;
			for (int pw = Integer.highestOneBit(n); pw > 0; pw >>= 1)
				if (i + pw <= n && tree[i + pw] <= k)
					k -= tree[i += pw];
			return i;
		}
	}

	// Digit DP
	public static int ddp(int n) {
		number = new StringBuilder(String.valueOf(n));
		digitDP = new int[12][12][2];
		for (int[][] a : digitDP)
			for (int[] b : a)
				Arrays.fill(b, -1);
		return call(0, 0, 0);
	}

	// Digit DP
	public static int call(int pos, int cnt, int f) {
		if (cnt > times)
			return 0;
		if (pos == number.length())
			return cnt == times ? 1 : 0;
		if (digitDP[pos][cnt][f] != -1)
			return digitDP[pos][cnt][f];
		int res = 0;
		int lmt = f == 0 ? number.charAt(pos) - '0' : 9;
		for (int dgt = 0; dgt <= lmt; ++dgt)
			if ((dgt == digit ? 1 + cnt : cnt) <= times)
				res += call(1 + pos, dgt == digit ? 1 + cnt : cnt, f == 0 && dgt < lmt ? 1 : f);
		digitDP[pos][cnt][f] = res;
		return res;
	}

	// Binary Exponentiation
	public static long binpow(long a, long n, long mod) {
		// Iterative approach
		a %= mod;
		long result = 1l;
		while (n > 0l) {
			if ((n & 1l) != 0l)
				result = result * a % mod;
			a = a * a % mod;
			n >>= 1l;
		}
		return result;

		// Recursive approach
		/*
		 * if (n == 0l) return 1l; long res = binpow(a, n / 2, mod); if ((n & 1l) != 0l)
		 * return ((res % mod) * (res % mod) * (a % mod)) % mod; else return ((res %
		 * mod) * (res % mod)) % mod;
		 */
	}

	// GCD
	public static int gcd(int a, int b) {
		while (b > 0) {
			a %= b;
			int t = a;
			a = b;
			b = t;
		}
		return a;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine().trim());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		float nextFloat() {
			return Float.parseFloat(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			StringBuilder str = new StringBuilder("");
			try {
				str.append(br.readLine().trim());
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str.toString();
		}

		int[] readArray(int size) {
			int[] ar = new int[size];
			for (int i = 0; i < size; ++i)
				ar[i] = nextInt();
			return ar;
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}