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.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;


public class Main{



    static long MOD = 1_000_000_007L;
    //static long MOD = 998_244_353L;
    //static long MOD = 1_000_000_033L;
    static long [] fac;
    static long [] pow;
    static long [] inv;
    static int[][] dir = new int[][]{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
    static long lMax = 0x3f3f3f3f3f3f3f3fL;
    static int iMax = 0x3f3f3f3f;
    static HashMap <Long, Long> memo = new HashMap();
    static HashMap <Long, Long> memof = new HashMap();
    static HashMap <Long, Long> memogL = new HashMap();
    static HashMap <Long, Long> memogR = new HashMap();
    static MyScanner sc = new MyScanner();
    //static ArrayList <Integer> primes;

    static long[] pow2;
    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        // Start writing your solution here. -------------------------------------
        int t = sc.nextInt();
        //int t = 1;

        int nn = 10000;
        /*fac = new long[nn + 1];
        fac[1] = 1;
        for(int i = 2; i <= nn; i++)
            fac[i] = fac[i - 1] * 1L * i % MOD;*/

        /*pow = new long[nn + 1];
        pow[0] = 1L;
        for(int i = 1; i <= nn; i++)
            pow[i] = pow[i - 1] * 2L % MOD;
        pow[1] = 3L;*/

        /*pow2 = new long[nn + 1];
        pow2[0] = 1L;
        for(int i = 1; i <= nn; i++)
            pow2[i] = pow2[i - 1] * 2L % (MOD - 1);*/

        /*inv = new long[nn + 1];
        inv[1] = 1;
        for (int i = 2; i <= nn; ++i)
            inv[i] = (MOD - MOD / i) * inv[(int)(MOD % i)] % MOD;*/


        //primes = sieveOfEratosthenes(100001);

        // 14, [1, 2, 2, 4, 5, 5, 4, 8, 8, 9, 9, 12, 12], [2, 3, 4, 5, 6, 7, 8, 9, 12, 10, 11, 13, 14]
        while(t-- > 0){
            //Solution sol = new Solution();
            //out.println(sol.minDist(5,5,1,5,new int[][]{{1,2,4,2},{1,5,10,3},{3,5,6,3},{2,4,4,3},{4,5,2,1}}));
            solve();
            //out.println(res);
        }
        out.close();
    }
    static boolean [] visited;
    static ArrayList<Integer>[] neigh;
    static int loopRoot;
    static ArrayList <Integer> cycle;
    static boolean loopEnd;
    static long cnt;

    static int total = 0;
    static long inv2 = (MOD + 1) / 2;


    static void solve() {
        long res = 100000000L;
        int n = sc.nextInt();
        int[] l = new int[n], r = new int[n];
        TreeSet <Integer> set = new TreeSet();
        for(int i = 0; i < n; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            set.add(l[i]);
            set.add(r[i]);
        }
        int cnt = 1;
        HashMap <Integer, Integer> map = new HashMap();
        for(int i : set) map.put(i, cnt++);
        int[] pre = new int[cnt + 1];
        int[] post = new int[cnt + 1];
        for(int i = 0; i < n; i++){
            l[i] = map.get(l[i]);
            r[i] = map.get(r[i]);
            pre[r[i] + 1]++;
            post[l[i] - 1]++;
        }
        for(int i = 1; i <= cnt; i++)
            pre[i] += pre[i - 1];
        for(int i = cnt - 1; i >= 0; i--)
            post[i] += post[i + 1];
        for(int i = 0; i < n; i++){
            res = Math.min(res, pre[l[i]] + post[r[i]]);
        }
        /*System.out.println(map);
        System.out.println(set);
        System.out.println(Arrays.toString(pre));
        System.out.println(Arrays.toString(post));
        System.out.println(Arrays.toString(l));
        System.out.println(Arrays.toString(r));
        System.out.println();*/
        out.println(res);
    }


    public static double dist(double a, double b){
        return Math.sqrt(a * a + b * b);
    }

    public static long inv(long a){
        return quickPOW(a, MOD - 2);
    }

    public class Interval {
        int start;
        int end;
        public Interval(int start, int end) {
            this.start = start;
            this.end = end;
        }
    }

    public static ArrayList<Integer> sieveOfEratosthenes(int n) {
        boolean prime[] = new boolean[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * 2; i <= n; i += p) {
                    prime[i] = false;
                }
            }
        }
        ArrayList<Integer> primeNumbers = new ArrayList<>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }


    public static int lowerBound(int[] a, int v){ return lowerBound(a, 0, a.length, v); }
    public static int lowerBound(int[] a, int l, int r, int v)
    {
        if(l > r || l < 0 || r > a.length)throw new IllegalArgumentException();
        int low = l-1, high = r;
        while(high-low > 1){
            int h = high+low>>>1;
            if(a[h] >= v){
                high = h;
            }else{
                low = h;
            }
        }
        return high;
    }
    public static long C(int n, int m)
    {
        if(m == 0 || m == n) return 1l;
        if(m > n || m < 0) return 0l;
        long res = fac[n] * quickPOW((fac[m] * fac[n - m]) % MOD, MOD - 2) % MOD;

        return res;
    }
    public static long quickPOW(long n, long m)
    {
        long ans = 1l;
        while(m > 0)
        {
            if(m % 2 == 1)
                ans = (ans * n) % MOD;
            n = (n * n) % MOD;
            m >>= 1;
        }
        return ans;
    }

    public static int gcd(int a, int b)
    {
        if(a % b == 0) return b;
        return gcd(b, a % b);
    }
    public static long gcd(long a, long b)
    {
        if(a % b == 0) return b;
        return gcd(b, a % b);
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}
