You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i.

The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero (exactly one) who is going to enter the dungeon this day.

When the hero enters the dungeon, he is challenged by the first monster which was not defeated during the previous days (so, if the heroes have already defeated k monsters, the hero fights with the monster k + 1). When the hero fights the monster, there are two possible outcomes:

  * if the monster's power is strictly greater than the hero's power, the hero retreats from the dungeon. The current day ends; 
  * otherwise, the monster is defeated. 



After defeating a monster, the hero either continues fighting with the next monster or leaves the dungeon. He leaves the dungeon either if he has already defeated the number of monsters equal to his endurance during this day (so, the i-th hero cannot defeat more than s_i monsters during each day), or if all monsters are defeated — otherwise, he fights with the next monster. When the hero leaves the dungeon, the current day ends.

Your goal is to defeat the last monster. What is the minimum number of days that you need to achieve your goal? Each day you have to use exactly one hero; it is possible that some heroes don't fight the monsters at all. Each hero can be used arbitrary number of times.

Input

The first line contains one integer t (1 ≤ t ≤ 10^5) — the number of test cases. Then the test cases follow.

The first line of each test case contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of monsters in the dungeon.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9), where a_i is the power of the i-th monster.

The third line contains one integer m (1 ≤ m ≤ 2 ⋅ 10^5) — the number of heroes in your party.

Then m lines follow, each describing a hero. Each line contains two integers p_i and s_i (1 ≤ p_i ≤ 10^9, 1 ≤ s_i ≤ n) — the power and the endurance of the i-th hero.

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

Output

For each test case print one integer — the minimum number of days you have to spend to defeat all of the monsters (or -1 if it is impossible).

Example

Input


2
6
2 3 11 14 1 8
2
3 2
100 1
5
3 5 100 2 3
2
30 5
90 1


Output


5
-1
import java.io.*;
import java.util.*;
import java.math.BigInteger; 

public class test {
    static class SegmentTreeRMQ 
    { 
    int st[]; 
    int minVal(int x, int y) { 
        return (x > y) ? x : y; 
    } 
  
    
    int getMid(int s, int e) { 
        return s + (e - s) / 2; 
    } 
  
    
    int RMQUtil(int ss, int se, int qs, int qe, int index) 
    { 
        
        if (qs <= ss && qe >= se) 
            return st[index]; 
  
        // If segment of this node is outside the given range 
        if (se < qs || ss > qe) 
            return Integer.MIN_VALUE; 
  
        // If a part of this segment overlaps with the given range 
        int mid = getMid(ss, se); 
        return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), 
                RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); 
    } 
  
    // Return minimum of elements in range from index qs (query 
    // start) to qe (query end).  It mainly uses RMQUtil() 
    int RMQ(int n, int qs, int qe) 
    { 
        // Check for erroneous input values 
        
  
        return RMQUtil(0, n - 1, qs, qe, 0); 
    } 
  
    // A recursive function that constructs Segment Tree for 
    // array[ss..se]. si is index of current node in segment tree st 
    int constructSTUtil(int arr[], int ss, int se, int si) 
    { 
        // If there is one element in array, store it in current 
        //  node of segment tree and return 
        if (ss == se) { 
            st[si] = arr[ss]; 
            return arr[ss]; 
        } 
  
        // If there are more than one elements, then recur for left and 
        // right subtrees and store the minimum of two values in this node 
        int mid = getMid(ss, se); 
        st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), 
                constructSTUtil(arr, mid + 1, se, si * 2 + 2)); 
        return st[si]; 
    } 
  
    
    void con(int arr[]) 
    { 
        // Allocate memory for segment tree 
  
        //Height of segment tree 
        int n = (arr.length);
        int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
  
        //Maximum size of segment tree 
        int max_size = 2 * (int) Math.pow(2, x) - 1; 
        st = new int[max_size]; // allocate memory 
  
        // Fill the allocated memory st 
        constructSTUtil(arr, 0, n - 1, 0); 
    }
    }
     static class DSU {
    
    int[] p;int[] sz;int op;int c;;
    int[] last;
    public void G(int n)
    {
        last=new int[n];
        p=new int[n];
        sz=new int[n];c=n;
        op=n;
        for(int h=0;h<n;h++)
        {
            sz[h]=1;p[h]=h;
            last[h]=h;
        }
    }
    public int find(int x)
    {
        int y=x;
        while(x!=p[x]) x=p[x];
        while(y!=p[y])
        {
            int tem=p[y];
            p[y]=x;y=tem;
        }
        return p[y];
    }
    public void union(int a,int b)
    {
        int x,y;
        x=find(a);y=find(b);
        if(x==y) return;
        if(sz[x]>sz[y])
        {
            p[y] = x;
            sz[x]+=sz[y];
            last[x]=Math.max(last[x],last[y]);
        }
        else
        {
            p[x]=y;sz[y]+=sz[x];
            last[y]=Math.max(last[y],last[x]);
        }
        c--;
        
    }}
    static int[][] dir={{0,1},{1,0},{-1,0},{0,-1}};
   static class sort implements Comparator<int[]>
   {
        public int compare(int[] a,int[] b)
        {
            if(a[0] == b[0]) return a[1]-b[1];
           return a[0]-b[0];
        }
   }
   public static void print(Object o)
   {
     PrintWriter out = new PrintWriter(System.out);;;
    out.println(o.toString());
    out.flush();
   }
   public static int intIn(String st)
   {
      return Integer.parseInt(st);
   }
   
   
    public static long Dis(int a,int b,int[][] arr)
    {
        long sum =0l;
        for(int[] x : arr)
        {
            sum = sum + Math.abs(a-x[0]) +Math.abs(b-x[1]) + 0l;
        }
        return sum;
    }
    public static void pr(Object o)
    {
        System.out.println(o.toString());
    }
    public static void prW(Object o)
    {
        System.out.print(o.toString());
    }
    public static long F(int a,int b)
    {
        return (1337317l)*a + (337133731l)*b;
    }
   
    public static int inInt(String s)
    {
        return Integer.parseInt(s);
    }
    public static long in(String s)
    {
        return Long.parseLong(s);
    }

    static long power(long x, long y, long p)
      {
        long res = 1; // Initialize result
     
        x = x % p; // Update x if it is more than or
        // equal to p
     
        if (x == 0)
          return 0l; // In case x is divisible by p;
     
        while (y > 0)
        {
     
          // If y is odd, multiply x with result
          if ((y & 1) != 0)
            res = (res * x) % p;
     
          // y must be even now
          y = y >> 1; // y = y/2
          x = (x * x) % p;
        }
        return res;
      }
      static long gcd(long a, long b)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b); 
        }
        static int gcd(int a, int b,int o)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b,o); 
        }
    static int find_lcm(int a, int b) 
    { 
        return (a * b) / new BigInteger(a+"").gcd(new BigInteger(b+"")).intValue(); 
    } 
      
    
    static int rangeDivisor(int m, int n, int a) 
    { 
        // Find LCM of a and b 
        //int lcm = FindLCM(a, b); 
       
        int a_divisor = n / a - (m - 1) / a; 
        //int b_divisor = n / b - (m - 1) / b; 
       
        // Find common divisor by using LCM 
        return a_divisor;
    }
    static int[] toIntArray(String[] m) 
    { 
        int[] p=new int[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= inInt(m[o]);
        }
        return p;
    }
    
    public static void main (String[] args) throws Exception {
        
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        
        
        //int[] map=new int[1000001];
      
        int y=Integer.parseInt(bf.readLine());
        
        for(int h=0;h<y;h++)
        {

            
        
            String[] xlp = bf.readLine().split(" ");
            SegmentTreeRMQ tree= new SegmentTreeRMQ();
            int n,m;
            n=inInt(xlp[0]);//k=inInt(xlp[1]);
            int[] arr = toIntArray(bf.readLine().split(" "));
            xlp = bf.readLine().split(" ");
            //pr(arr.length);
            tree.con(arr);
           // int n,m;
            m=inInt(xlp[0]);
            int[][] pow=new int[m][3];
            for(int o=0;o<m;o++)
            {
                xlp = bf.readLine().split(" ");
                pow[o][0]= intIn(xlp[0]);
                pow[o][1] = intIn(xlp[1]);

            }
            Arrays.sort(pow,new sort());
            int s=0;
            for(int o=m-1;o>=0;o--)
            {
                pow[o][2] = Math.max(pow[o][1],s);
                s=pow[o][2];
            }
            int res=0;int maxP = pow[m-1][0];boolean bol=true;
            TreeMap<Integer,Integer> tm = new TreeMap<>();
            for(int o=0;o<m;o++)
            {
                if(!tm.containsKey(pow[o][0]))
                {
                    tm.put(pow[o][0],o);
                }
            }
            for(int o=0;o<n;)
            {
                if(maxP < arr[o])
                {
                    bol=false;break;
                }
                int low=1;
                int high = n-o;int ans=1;int mid;int max;
                    boolean bp;
                    Integer in ;
                while(low<high)
                {
                    mid = (low+ high)/2;
                    max = tree.RMQ(n,o,o+mid-1);
                     bp = false;
                     in = tm.ceilingKey(max);

                    if(in != null)
                    {
                        in  = tm.get(in);
                        bp = (pow[in][2] >= mid);
                    }
                     //pr(mid+" "+in+" "+bp);
                    if(bp)
                    {
                        ans = mid;
                        low = mid+1;
                    }
                    else
                    {
                        high=mid-1;
                    }
                }
                 mid = (low);
                    max = tree.RMQ(n,o,o+mid-1);
                     bp = false;
                    in = tm.ceilingKey(max);
                    if(in != null)
                    {
                        in  = tm.get(in);
                        bp = (pow[in][2] >= mid);
                    }
                    if(bp) ans=Math.max(ans,mid);
                    mid = (high);
                   max = tree.RMQ(n,o,o+mid-1);
                    bp = false;
                   in = tm.ceilingKey(max);
                    if(in != null)
                    {
                        in  = tm.get(in);
                        bp = (pow[in][2] >= mid);
                    }
                    if(bp) ans=Math.max(ans,mid);
               // pr(o+" "+ans);
                res++;

                o+=(ans);
            }
            if(!bol) pr(-1);
            else
            {
                pr(res);
            }









            
            
            









            
          
           
            

            

            
            
            
        }

    }
}
/*


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


*/


