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
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
*/
import java.util.*;
import java.io.*;

   public class D
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         for(int qw=0; qw < T; qw++)
         {
            st = new StringTokenizer(infile.readLine());
            int N = Integer.parseInt(st.nextToken());
            int[] arr = new int[N];
            st = new StringTokenizer(infile.readLine());
            int MAX = 0;
            for(int i=0; i < N; i++)
            {
               arr[i] = Integer.parseInt(st.nextToken());
               MAX = Math.max(MAX, arr[i]);
            }  
            //pls no tle
            int M = Integer.parseInt(infile.readLine());
            HashMap<Integer, Integer> boof = new HashMap<Integer, Integer>();
            for(int i=0; i < M; i++)
            {
               st = new StringTokenizer(infile.readLine());
               int p = Integer.parseInt(st.nextToken());
               int s = Integer.parseInt(st.nextToken());
               if(!boof.containsKey(p))
                  boof.put(p, 0);
               boof.put(p, Math.max(s, boof.get(p)));
            }
            //process
            ArrayList<Hero> ls = new ArrayList<Hero>();
            for(int k: boof.keySet())
               ls.add(new Hero(k, boof.get(k)));
            Collections.sort(ls);
            //value to index map
            TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
            for(int i=0; i < ls.size(); i++)
               map.put(ls.get(i).power, i);
            M = ls.size();
            RangeTree rmaxq = new RangeTree(M+1);
            for(int i=0; i < M; i++)
               rmaxq.update(i, i, -1*ls.get(i).stamina);
            //special
            if(ls.get(M-1).power < MAX)
            {
               System.out.println(-1);
               continue;
            }
            //solve
            int res = 0;
            int cm = 0;
            while(cm < N)
            {
               int most = arr[cm];
               int start = cm;
               int maxDist = 1;
               int i;
               for(i=cm+1; i < N; i++)
               {
                  most = Math.max(most, arr[i]);
                  int dex = map.get(map.ceilingKey(most));
                  int maxlen = -1*(int)rmaxq.minQuery(dex, M);
                  if(start+maxlen-1 < i)
                  {
                     cm = i;
                     break;
                  }
               }
               if(i >= N)
                  cm = N;
               res++;
            }
            System.out.println(res);
         }
      }
   }
   class Hero implements Comparable<Hero>
   {
      public int power;
      public int stamina;
      
      public Hero(int a, int c)
      {
         power = a; 
         stamina = c;
      }
      public int compareTo(Hero oth)
      {
         if(power == oth.power)
            return stamina-oth.stamina;
         return power-oth.power;
      }
   }
   class RangeTree 
   {
		private long[] min;
		private long[] lazy;
		private long[] sum;
		private int size;
		public RangeTree(int size) 
      {
			this.size = size;
			min = new long[4*size];
			sum = new long[4*size];
			lazy = new long[4*size];
		}
		public void update(int l, int r, int inc) 
      {
			update(1, 0, size-1, l, r, inc);
		}
		private void pushDown(int index, int l, int r) 
      {
			min[index] += lazy[index];
			sum[index] += lazy[index] * (r-l+1);
			if(l != r) 
         {
				lazy[2*index] += lazy[index];
				lazy[2*index+1] += lazy[index];
			}
			lazy[index] = 0;
		}
		private void pullUp(int index, int l, int r) 
      {
			int m = (l+r)/2;
			min[index] = Math.min(evaluateMin(2*index, l, m), evaluateMin(2*index+1, m+1, r));
			sum[index] = evaluateSum(2*index, l, m) + evaluateSum(2*index+1, m+1, r);
		}
		private long evaluateSum(int index, int l, int r) 
      {
			return sum[index] + (r-l+1)*lazy[index];
		}
		private long evaluateMin(int index, int l, int r) 
      {
			return min[index] + lazy[index];
		}
		private void update(int index, int l, int r, int left, int right, int inc) 
      {
			if(r < left || l > right) return;
			if(l >= left && r <= right) {
				lazy[index] += inc;
				return;
			}
			pushDown(index, l, r);
			int m = (l+r)/2;
			update(2*index, l, m, left, right, inc);
			update(2*index+1, m+1, r, left, right, inc);
			pullUp(index, l, r);
		}
		public long minQuery(int l, int r) 
      {
			return minQuery(1, 0, size-1, l, r);
		}
		private long minQuery(int index, int l, int r, int left, int right) 
      {
			if(r < left || l > right) return Long.MAX_VALUE;
			if(l >= left && r <= right) {
				return evaluateMin(index, l, r);
			}
			pushDown(index, l, r);
			int m = (l+r)/2;
			long ret = Long.MAX_VALUE;
			ret = Math.min(ret, minQuery(2*index, l, m, left, right));
			ret = Math.min(ret, minQuery(2*index+1, m+1, r, left, right));
			pullUp(index, l, r);
			return ret;
		}
		public long sumQuery(int l, int r) 
      {
			return sumQuery(1, 0, size-1, l, r);
		}
		private long sumQuery(int index, int l, int r, int left, int right) 
      {
			if(r < left || l > right) return 0;
			if(l >= left && r <= right) {
				return evaluateSum(index, l, r);
			}
			pushDown(index, l, r);
			int m = (l+r)/2;
			long ret = 0;
			ret += sumQuery(2*index, l, m, left, right);
			ret += sumQuery(2*index+1, m+1, r, left, right);
			pullUp(index, l, r);
			return ret;
		}
	}