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.*;

public class Main 
{
	public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in) ; 
		PrintWriter out =new PrintWriter(System.out) ;
		
		int TC = sc.nextInt() ; 
		outer:
		while(TC-->0)
		{
			
			int n = sc.nextInt(); 
			int [] a = new int [n] ; 
			for(int i = 0 ; i < n ; i++)
				a[i] = sc.nextInt() ; 
			SparseTable sp = new SparseTable(a);
			
			TreeSet<Hero> set = new TreeSet<>();
			int m = sc.nextInt() ; 
			Compressor<Integer> comp = new Compressor<Integer>();
			for(int i = 0 ; i < m ; i ++)
			{
				Hero h = null;
				set.add(h = new Hero(sc.nextInt() , sc.nextInt())) ; 
				comp.add(h.p);
			}
			comp.fix();
			int [] P = new int [comp.set.size()];
			
			for	(Hero h : set)
			{
				int x = comp.get(h.p);
				P[x] = Math.max(P[x] , h.s);
			}
			SparseTable sp1 = new SparseTable(P);
			long ans = 0 ; 
			for(int i = 0 ; i < n ; i++)
			{
				int nxt = -1 ; 
				int start = i , end = n - 1 ; 
				
				while(start <= end)
				{
					int mid = start + end >> 1 ; 
					int max = sp.query(i, mid) ;
					if(comp.get(max) == null || sp1.query(comp.get(max), P.length - 1) < mid - i + 1)
					{
						end = mid - 1 ; 
					}
					else {
						nxt = mid ; 
						start = mid + 1 ; 
					}
					
				}
				if(nxt == -1)
				{
					out.println(-1);
					continue outer ; 
				}
				int max = sp.query(i, nxt) ; 
				int s =sp1.query(comp.get(max), P.length - 1) ; 
				int freq = nxt - i + 1 ; 
				ans += (freq + s - 1) / s ; 
				i = nxt ; 
			}
			out.println(ans);
		}
		out.flush();
		
	}
	static class SparseTable 
	{

		int A[], SpT[][];

		SparseTable(int[] A) 
		{
			
			int n = A.length;
			this.A = A;
			int k =(int) Math.floor((Math.log(n) / Math.log(2)))+ 1;
			SpT = new int[n][k];

			for (int i = 0; i < n; i++)
				SpT[i][0] = i;
				
			for (int j = 1; (1 << j) <= n; j++)
				for (int i = 0; i + (1 << j) - 1 < n; i++)
					if (A[SpT[i][j - 1]] > A[SpT[i + (1 << (j - 1))][j - 1]])
						SpT[i][j] = SpT[i][j - 1];
					else 
						SpT[i][j] = SpT[i + (1 << (j - 1))][j - 1];
		}

		int query(int i, int j) 
		{

			if(j - i + 1 < 0)return -1 ; 
			int k =(int) Math.floor((Math.log(j - i + 1) / Math.log(2)));

			if (A[SpT[i][k]] >= A[SpT[j - (1 << k) + 1][k]])
				return A[SpT[i][k]];
			else
				return A[SpT[j - (1 << k) + 1][k]];
		}

	}
	static class Compressor<T> implements Iterable<T>
	{
		TreeSet<T> set = new TreeSet<>() ; 
		TreeMap<T , Integer> map = new TreeMap<>() ; 
		
		void add(T x) {set.add(x);}
		
		void fix() {for(T x : set) map.put(x, map.size()) ;}
		
		Integer get(T x) {
			if(map.ceilingEntry(x) == null)return null ; 
			return map.ceilingEntry(x).getValue() ;
		}

		public Iterator<T> iterator() {return set.iterator();}
	}
	static class Hero implements Comparable<Hero>
	{
		int p , s ; 
		Hero(int a , int b)
		{
			p = a ; 
			s = b ; 
		}
		@Override
		public int compareTo(Hero o) 
		{
			long val1 = p * 1l *((int)1e9) + s ; 
			long val2 = o.p * 1l *((int)1e9) + o.s ; 
			
			return Long.compare(val1, val2);
		}
		@Override
		public String toString() {
			
			return p+" "+s;
		}
	}
	
	static class Scanner 
	{
		StringTokenizer st;
		BufferedReader br;
 
		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public int nextInt() throws IOException 
		{
			return Integer.parseInt(next());
		}
 	}
}