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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.stream.Stream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


public class Main {
	

static class Seg implements Comparable<Seg>{
	
	int l, r;
	public Seg(int l, int r) {
		this.l = l;
		this.r = r;
	}
	@Override
	public int compareTo(Seg o) {
		
		return Integer.compare(l, o.l);
	}
	
}

static class BIT_RangeQueryPointUpdate {
	int[]bit;
	int n;
	public BIT_RangeQueryPointUpdate(int[]a, int n) {
		this.n = n;
		this.bit = new int[n+10];
	}
	public BIT_RangeQueryPointUpdate(int n) {
		this.n = n;
		this.bit = new int[n+10];
	}
	public void init_tree(int[]a) {
		Arrays.fill(this.bit, 0);
		for(int i = 0; i < n; i++) {
			this.add(i, a[i]);
		}
	}
	public int sumQuery(int ind) {
		int sum = 0;
		ind++;
		for(; ind > 0; ind -= ind & (-ind)) {
			sum += bit[ind];
		}
		return sum;
	}
	public void add(int ind, int val) {
		ind++;
		for(; ind <= n; ind += ind & (-ind)) {
			bit[ind] += val;
		}
	}
	public int sumInRange(int l, int r) {
		return sumQuery(r) - sumQuery(l - 1);
	}
	
}
	

public static void main(String[] args){
 
   new Thread(null, null, "Anshum Gupta", 99999999) {
        public void run() {
            try {
                solve();
            } catch(Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }.start();
}
 

static final long INF_LONG = (long)(1e18 + 5), MOD = (long)1e9 + 7;//998244353; 
static final int MXN = (int)(1001), MXV = (int)(2e5 + 5), log = 18, INF = (int)1e9 + 500;
static boolean[] vis;
static ArrayList<ArrayList<Integer>> adj;
static int n, m, q, k, h, w;
static char[] str;
static int[] a, pre;



public static void solve() throws Exception {
	   // solve the problem here
		s = new MyScanner();
   		out = new MyWriter(new BufferedOutputStream(System.out));
   		
   		
   		
   		
        int tc = s.nextInt();   
    	for(int i=1; i<=tc; i++) {
    		testcase();
    	}
          
        out.flush();
        out.close();
}





static void testcase() {
	
	int n = s.nextInt();
	Seg[] segs = new Seg[n];
	for(int i = 0; i < n; i++) segs[i] = new Seg(s.nextInt(), s.nextInt());
	
	TreeSet<Integer> dist = new TreeSet<>();
	for(int i = 0; i < n; i++) {
		dist.add(segs[i].l);
		dist.add(segs[i].r);
	}
	
	HashMap<Integer, Integer> mp = new HashMap<>();
	int ind = 0;
	int size = dist.size();
	while(!dist.isEmpty()) {
		mp.put(dist.pollFirst(), ind++);
	}
	
//	out.println("size = " + size);
	
	BIT_RangeQueryPointUpdate endPoints = new BIT_RangeQueryPointUpdate(size + 1),
			startPoints = new BIT_RangeQueryPointUpdate(size + 1);
	
	
	for(int i = 0; i < n; i++) {
		segs[i].l = mp.get(segs[i].l);
		segs[i].r = mp.get(segs[i].r);
	}
	
	for(int i = 0; i < n; i++) {
		startPoints.add(segs[i].l, 1);
		endPoints.add(segs[i].r, 1);
	}
	
	int ans = n - 1;
	
	for(int i = 0; i < n; i++) {
		
		int sb = startPoints.sumInRange(segs[i].r + 1, size); 
		int ea = endPoints.sumInRange(0, segs[i].l - 1);
		
//		out.println("i = " + i + " sb = " + sb + " ea = " + ea);
		
		ans = Math.min(ans, sb + ea);
		
	}
	
	out.println(ans);
	
	
	
}




public static MyWriter out;
public static MyScanner s;
static void shuffleArray(int[] a) {
	Random random = new Random();
	for (int i = a.length-1; i > 0; i--) {
		int index = random.nextInt(i + 1);
		int tmp = a[index];
		a[index] = a[i];
		a[i] = tmp;
	}
}
static void shuffleSort(int[] a) {
	shuffleArray(a);
	Arrays.parallelSort(a);
}
static class MyScanner {
 
    BufferedReader br;
    StringTokenizer st;
 
    public MyScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    public MyScanner(String fileName) {
    	try {
			br = new BufferedReader(new FileReader(fileName));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
    }
    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()); }
    int[] nextIntArray(int n){
    	int[]a = new int[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    long[] nextlongArray(int n) {
    	long[]a = new long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    Integer[] nextIntegerArray(int n){
    	Integer[]a = new Integer[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextInt();
    	}
    	return a;
    }
    Long[] nextLongArray(int n) {
    	Long[]a = new Long[n];
    	for(int i=0; i<n; i++) {
    		a[i] = this.nextLong();
    	}
    	return a;
    }
    char[][] next2DCharArray(int n, int m){
    	char[][]arr = new char[n][m];
    	for(int i=0; i<n; i++) {
    		arr[i] = this.next().toCharArray();
    	}
    	return arr;
    }
    ArrayList<ArrayList<Integer>> readUndirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    		adj.get(v).add(u);
    	}
    	return adj;
    }
    ArrayList<ArrayList<Integer>> readDirectedUnweightedGraph(int n, int m) {
    	ArrayList<ArrayList<Integer>>adj = new ArrayList<ArrayList<Integer>>();
    	for(int i=0; i<=n; i++)adj.add(new ArrayList<Integer>());
    	for(int i=0; i<m; i++) {
    		int u = s.nextInt();
    		int v = s.nextInt();
    		adj.get(u).add(v);
    	}
    	return adj;
    }
    String nextLine(){
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }
}
 
static class MyWriter extends PrintWriter {
    MyWriter(OutputStream out) {
        super(out);
    }
    void println(int[] x) {
        println(x, " ");
    }
    void println(int[] x, String delimiter) {
        if (x.length > 0) {
            print(x[0]);
            for (int i = 1; i < x.length; i++) {
                print(delimiter);
                print(x[i]);
            }
        }
        println();
    }
    void println(long[] x) {
        println(x, " ");
    }
    void println(long[] x, String delimiter) {
        if (x.length > 0) {
            print(x[0]);
            for (int i = 1; i < x.length; i++) {
                print(delimiter);
                print(x[i]);
            }
        }
        println();
    }
    void println(Iterable<?> iterable) {
        println(iterable, " ");
    }
    void println(Iterable<?> iterable, String delimiter) {
        Iterator<?> i = iterable.iterator();
        if (i.hasNext()) {
            print(i.next());
            while (i.hasNext()) {
                print(delimiter);
                print(i.next());
            }
        }
        println();
    }
    void printLines(int[] x) {
        println(x, System.lineSeparator());
    }
    void printLines(long[] x) {
        println(x, System.lineSeparator());
    }
    void printLines(Iterable<?> iterable) {
        println(iterable, System.lineSeparator());
    }
}
 
}