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
//package learning;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class NitsLocal {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
    
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k<= n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
           //sieve();
                prime[1] = false;
                /*
              int n = sc.ni();     
              int []a = sc.nia(n);
              int mod = 1000000007;
              long ans = 0;
              int f = 0;
              int q = sc.ni();
              while(q-- > 0)
              {
                  int num = sc.ni();
                  ans = 0;
                  if(num == 0)
                  {
                      a[sc.ni()-1] = sc.ni();
                  }
                 else
                  {
                      int l = sc.ni();
                      int r = sc.ni();
                    for(int i=l-1;i<r;i++)
                   {
                  
                   for(int j=i+1;j<r;j++)
                   {
                      f = 0;
                   
                      int x = a[i];
                      int y = a[j];
                      while(x > 0 && y > 0)
                      {
                          int y1 = x%10;
                          int y2 = y%10;
                          if(y1 > 0 && y2 > 0)
                          {
                              f = 1;
                          }
                          x /= 10;
                          y /= 10;
                      }
                      
                    
                    
                   
                     if(f==0)
                     {
                         ans = (ans + ((((long)a[i]%mod) * ((long)a[j]%mod)))%mod)%mod;
                     }
                  }
              }
              
              w.println(ans);
                  }
              }
          
            */
                int t = sc.ni();
                while(t-- > 0)
                {
                   int n = sc.ni();
                   int []a = sc.nia(n);
                   int m = sc.ni();
                   //Arrays.sort(a);
                   ArrayList<Temp> st = new ArrayList<>();
                   for(int i=0;i<m;i++)
                   {
                       st.add(new Temp(sc.ni(),sc.ni(),0,0));
                   }
                   Collections.sort(st, 
                new CustomerSortingComparator());
                   //w.println(st.get(0).a);
                int l = 1;
                int []dp = new int[n+1];
                  for(int i=0;i<st.size();i++)
                  {
                      int t1 = st.get(i).b;
                      if(t1 >= l)
                      {
                          while(l <= t1)
                          {
                              dp[l] = st.get(i).a;
                              l++;
                          }
                      }
                      
                      
                  }
                  int cnt = -1;
                  int f = 0;
                  int res = 0;
                  while(cnt < n)
                  {
                      int x = 0;
                      if(cnt >= n-1)
                          break;
                      if(a[cnt+1]> dp[1])
                      {
                          f = 1;
                          break;
                      }
                      int x1 = 1;
                      int l1 = 1;
                      int max = a[cnt+x1];
                      while(max <= dp[x1])
                      {
                          x1++;
                          
                          if(cnt+x1 >=n)
                          {
                             
                              break;
                          }
                          max = Math.max(max,a[cnt+x1]);
                          
                      }
                      res++;
                     
                   
                      cnt += (x1-1);
                       //w.println(res + " " + cnt);
                   
                      
                      
                  }
                  
                  if(f==0)
                  w.println(res);
                  else
                      w.println("-1");
                   
               
          
                    
                }
               
                
        
      
       w.close();
       
        
    }
    public static int upperBound(int []arr,int n,int num)
    {
        int l = 0;
        int r = n;
        while(l < r)
        {
            int mid = (l+r)/2;
            if(num >= arr[mid])
            {
                l = mid +1;
            }
            else
                r = mid;
        }
        return l;
    }
    public static int countSetBits(int number){
        int count = 0;
        while(number>0){
            ++count;
            number &= number-1;
        }
        return count;
    }
    
     static  class CustomerSortingComparator 
                                implements Comparator<Temp> {
 
    @Override
    public int compare(Temp cust1, Temp cust2) {
 
        // all comparison
        int compareName = 0;
        if(cust1.a < cust2.a)
            return 1;
        
        else if(cust1.a > cust2.a)
        return -1;
        else
        {
            if(cust1.b < cust2.b)
                return 1;
            else
                return -1;
            
        }
       
        }
    
    }
      

    public static long pow(long i, long j) {
		long res=1L;
		for(int a=0;a<j;a++) res*=i;
		return res;
	}
    public static long powmod(long i, long j,long MOD) {
		if(j==0) return 1L;
		if(j%2==0) {
			long temp=powmod(i,j/2,MOD);
			return (temp*temp)%MOD;
		}
		return (i*powmod(i,j-1,MOD))%MOD;
	}
    static HashSet<Integer> fac;
    public static void primeFactors(int n) 
    { 
        // Print the number of 2s that divide n 
        int t = 0;
        while (n%2==0) 
        { 
            fac.add(2);
            n /= 2; 
        } 
  
        // n must be odd at this point.  So we can 
        // skip one element (Note i = i +2) 
        for (int i = 3; i*i <= n; i+= 2) 
        { 
            // While i divides n, print i and divide n 
            while (n%i == 0) 
            { 
                fac.add(i);
                n /= i; 
            } 
        } 
  
        // This condition is to handle the case whien 
        // n is a prime number greater than 2 
        if (n > 2) 
            fac.add(n);
    } 
     static long modexp(long x,long n,long M)
{
    long power = n;
    long result=1;
    x = x%M;
    while(power>0)
    {
        if(power % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        power = power/2;
    }
    return result;
}
    static int gcd(int a,int b)
    {
        if(a==0)
            return b;
        else
            return gcd(b%a,a);
    }
    static class Temp{
        int a;
        int b;
        int c;
        int d;
      
        Temp(int a,int b,int c,int d)
        {
            this.a = a;
            this.b = b;
            this.c  =c;
            this.d = d;
            //this.d = d;
        }
    }
    static class Query{
        int p;
        int index;
        int value;
        public Query(int p,int index,int value)
        {
            this.p = p;
            this.index = index;
            this.value = value;
            
        }
    }
    static int nextPowerOf2(int n) 
    { 
        int count = 0; 
  
        // First n in the below  
        // condition is for the  
        // case where n is 0 
        if (n > 0 && (n & (n - 1)) == 0) 
            return n; 
  
        while(n != 0) 
        { 
            n >>= 1; 
            count += 1; 
        } 
  
        return 1 << count; 
    } 
    
   static long sum1(int t1,int t2,int x,int []t)
   {
       int mid = (t2-t1+1)/2;
  if(t1==t2)
      return 0;
    
   else
   return sum1(t1,mid-1,x,t) + sum1(mid,t2,x,t);
    
     
   }
  
   
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
         
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
if (snumChars == -1)
throw new InputMismatchException();
if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
}
return buf[curChar++];
}
 
public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
           
        }
        
    }
}