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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main7{

static class Pair
    { 
        int x;
		int y;
        public Pair(int x, int y) 
        {     
            this.x=x;
			this.y=y;
        }     
        
    @Override
            public int hashCode() 
            { 
                final int temp = 14; 
                int ans = 1; 
                ans =x*31+y*13; 
                return ans; 
            } 
      
            // Equal objects must produce the same 
            // hash code as long as they are equal 
        @Override
        public boolean equals(Object o) 
        { 
            if (this == o) { 
                return true; 
            } 
            if (o == null) { 
                return false; 
            } 
            if (this.getClass() != o.getClass()) { 
                return false; 
            } 
            Pair other = (Pair)o; 
            if (this.x != other.x || this.y!=other.y) { 
                return false; 
            } 
            return true; 
        } 
            
    } 
static class Pair1{
	int x;
	int y;
	long z;
	Pair1(int x, int y, long z)
	{
		this.x=x;
		this.y=y;
		this.z=z;
	}
}
    
    public static long pow(long a, long b)
    {
        long result=1;
        while(b>0)
        {
            if (b % 2 != 0)
            {
                result=(result*a)%1000000007;
                b--;
            } 
            a=(a*a)%1000000007;
            b /= 2;
        }   
        return result;
    }
    public static long fact(long num)
    {
                long value=1;
                long i=1;
                for(i=2;i<=num;i++)
                {
                    value=((value)*(long)i);
                }
                return value;
            }
            public static long gcd(long a, long b)
            {
                if (a == 0)
                    return b;
                return gcd(b%a, a);
            }
            
    /*        public static long lcm(long a,long b)
            {
                return a * (b / gcd(a, b));
            }
        */    public static long sum(int h)
            {
                return (h*(h+1)/2);
            }
        /*   public static void dfs(int parent,boolean[] visited,int[] dp)
            {
                ArrayList<Integer> arr=new ArrayList<Integer>();
                arr=graph.get(parent);
                visited[parent]=true;
                for(int i=0;i<arr.size();i++)
                {
                    int num=(int)arr.get(i);
                    if(visited[num]==false)
                    {
                        dfs(num,visited,dp);
                    }
                    dp[parent]=Math.max(dp[num]+1,dp[parent]);
                }
            }
        //    static int flag1=0;
            static int[] dis;*/
            static int mod=1000000007;
            static ArrayList<ArrayList<Integer>> graph;
            static ArrayList<ArrayList<Integer>> g;
            
       /*    public static void bfs(int num,int size)
            {
                boolean[] visited=new boolean[size+1];
                Queue<Integer> q=new LinkedList<>();
                q.add(num);
                ans[num]=1;
                visited[num]=true;
                while(!q.isEmpty())
                {
                    int x=q.poll();
                    ArrayList<Integer> al=graph.get(x);
                    for(int i=0;i<al.size();i++)
                    {
                        int y=al.get(i);    
                        if(visited[y]==false)
                        {
                            q.add(y);
                            ans[y]=ans[x]+1;
                            visited[y]=true;
                        }
                    }
                }
            }
            static int[] ans;*/
            static int[] tree;
    
			static int constructTree(int[] a, int start,int end,int index)
			{
				if(start==end)
				{
					tree[index]=a[start];
					return a[start];
				}
				int mid=(start+end)/2;
				tree[index]=Math.max(constructTree(a,start,mid,2*index+1),constructTree(a,mid+1,end,2*index+2));
				return tree[index];
			}
			static void updateTree(int[] a,int start,int end,int index,int value, int right_index)
			{
				if(right_index<start || end<right_index)
				{
					return ;
				}
				tree[index]=tree[index]+value;
				if(start!=end)
				{
					int mid=(start+end)/2;
					updateTree(a,start,mid,2*index+1,value,right_index);
					updateTree(a,mid+1,end,2*index+2,value,right_index);
				}
			}
			static int query(int start,int end, int left, int right,int index)
			{
				if(left<=start && right>=end)
				{
					return tree[index];    
				}
				if(end<left || start>right)
					return 0;
					
				int mid=(start+end)/2;
				return Math.max(query(start,mid,left,right,2*index+1),query(mid+1,end,left,right,2*index+2));
			}
					
			static public void main(String args[])throws IOException
            {
				int t=i();
				StringBuilder sb=new StringBuilder();
				while(t-->0)
				{
					int n=i();
					int[] a=new int[n];
					for(int i=0;i<n;i++)
					{
						a[i]=i();
					}
					int m=i();
					int[] p=new int[m];
					int[] s=new int[m];
					Pair[] pair=new Pair[m];
					for(int i=0;i<m;i++)
					{
						p[i]=i();
						s[i]=i();
						pair[i]=new Pair(p[i],s[i]);
					}
					Arrays.sort(pair,new Comparator<Pair>(){
						@Override
						public int compare(Pair p1, Pair p2)
						{
							if(p1.x<p2.x)
							{
								return -1;
							}
							else if(p1.x>p2.x)
							{
								return 1;
							}	
							else
							{
								if(p1.y>p2.y)
								{
									return 1;
								}
								else
									return -1;
							}
						
						}
					});
					int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
			  
					int max_size = 2 * (int) Math.pow(2, x) - 1; 
			  
					tree = new int[max_size];
					constructTree(a,0,n-1,0);
					
					int[] max=new int[m];
					for(int i=m-1;i>=0;i--)
					{
						if(i==m-1)
						{
							max[i]=pair[i].y;
						}
						else
						{
							max[i]=Math.max(max[i+1],pair[i].y);
						}
					}
					int flag=0;
					int day=0;
					int i=0;
					while(i<n)
					{
						int low=0;
						int high=n-i;
						int ans=0;
						while(low<=high)
						{
							int mid=low+(high-low)/2;
							boolean value=check(mid,n,i,m,pair,max);
							if(value==true)
							{
								ans=mid;
								low=mid+1;
							}
							else
							{
								high=mid-1;
							}
						}
						if(ans==0)
						{
							flag=1;
							break;
						}
						else
						{
							i=i+ans;
							day++;
						}
					}
					if(flag==1)
					{
						sb.append("-1\n");
					}
					else
					{
						sb.append(day+"\n");
					}
				}
				System.out.print(sb.toString());
			}
			static boolean check(int mid1,int n,int i,int m,Pair[] pair,int[] max)
			{
				int size=mid1;
				int max_in_range=query(0,n-1,i,i+size-1,0);
				int low=0;
				int high=m;
				int index=-1;
				int flag=0;
				while(low<high)
				{
					int mid=low+(high-low)/2;
					if(pair[mid].x>max_in_range)
					{
						high=mid;
					}
					else if(pair[mid].x<max_in_range)
					{
						low=mid+1;
					}
					else
					{
						flag=1;
						index=mid;
						break;
					}
				}
				if(flag==1)
				{
					if(max[index]>=size)
					{
						return true;
					}
					return false;
				}
				else
				{
					int index_find=low;
					if(index_find>=m)
						return false;
					if(max[index_find]>=size)
					{
						return true;
					}
					return false;
				}
			}
            /**/
            static InputReader in=new InputReader(System.in);
                static OutputWriter out=new OutputWriter(System.out);
                public static long l()
                {
                    String s=in.String();
                    return Long.parseLong(s);
                }
                public static void pln(String value)
                {
                    System.out.println(value);
                }
                public static int i()
                {
                    return in.Int();
                }
                public static String s()
                {
                    return in.String();
                }
    }
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        class InputReader {
             
            private InputStream stream;
            private byte[] buf = new byte[1024];
            private int curChar;
            private int numChars;
            private SpaceCharFilter filter;
         
            public InputReader(InputStream stream) {
                this.stream = stream;
            }
         
            public int read() {
                if (numChars== -1)
                    throw new InputMismatchException();
                if (curChar >= numChars) {
                    curChar = 0;
                    try {
                        numChars = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (numChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }
         
            public int Int() {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = read();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = read();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
         
            public String String() {
                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 boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
         
            public String next() {
                return String();
            }
         
            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
         
        class OutputWriter {
            private final PrintWriter writer;
         
            public OutputWriter(OutputStream outputStream) {
                writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
            }
         
            public OutputWriter(Writer writer) {
                this.writer = new PrintWriter(writer);
            }
         
            public void print(Object...objects) {
                for (int i = 0; i < objects.length; i++) {
                    if (i != 0)
                        writer.print(' ');
                    writer.print(objects[i]);
                }
            }
         
            public void printLine(Object...objects) {
                print(objects);
                writer.println();
            }
         
            public void close() {
                writer.close();
            }
         
            public void flush() {
                writer.flush();
            }
         
            }
         
            class IOUtils {
         
            public static int[] readIntArray(InputReader in, int size) {
                int[] array = new int[size];
                for (int i = 0; i < size; i++)
                    array[i] = in.Int();
                return array;
            }
         
            } 

