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

@SuppressWarnings("unused")
public class Main {
    FastScanner in;
    PrintWriter out;
    int MOD = (int)1e9+7;
    long ceil(long a, long b){return (a + b - 1) / b;}
    long gcd(long a, long b){return b == 0 ? a : gcd(b, a % b);}
    long lcm(long a, long b){return a / gcd(a, b) * b;}

    int INF = Integer.MAX_VALUE;
    int n, m;
    SegmentTree segMonster, segHero;

    void solve(){
        int t = in.nextInt();
        for (int i = 0; i < t; i++) {
            solveMain();
        }
    }

    void solveMain(){
        n = in.nextInt();
        segMonster = new SegmentTree(n);
        for (int j = 0; j < n; j++){
            int a = in.nextInt();
            segMonster.setPoint(j, a);
        }

        m = in.nextInt();
        segHero = new SegmentTree(n+1);
        for (int j = 0; j < m; j++) {
            int pow = in.nextInt();
            int len = in.nextInt();
            segHero.setPoint(len, pow);
        }
        segHero.setPoint(0, INF);

        int idx = 0, cnt = 0;
        while(true){
            int maxLen = calcMaxLen(idx);
            if(maxLen == 0){
                out.println("-1");
                return;
            }
            cnt++;
            idx += maxLen;
            if(idx >= n) break;
        }
        out.println(cnt);
    }
    //end solve

    int calcMaxLen(int idx){
        int ok = 0, ng = n+1;
        while(ng - ok > 1){
            int mid = (ok + ng) / 2;
            int maxMonster = (int)segMonster.getSegment(idx, Math.min(idx+mid, n));
            int maxHero = (int)segHero.getSegment(mid, n+1);
            if(maxHero >= maxMonster) ok = mid;
            else ng = mid;
        }
        return ok;
    }

    class SegmentTree{
        int d;
        long[] node;

        /*二項演算で使える単位元*/
        private long e = 0;

        /*結合律が成り立つ、要素同士の二項演算*/
        private long f(long e1, long e2){
            return Math.max(e1, e2);
        }

        /*要素更新用の演算(可換でなくてもよい)*/
        private long g(long nodeVal, long val){
            return Math.max(nodeVal, val);
        }

        /* 単位元で初期化 */
        public SegmentTree(int sz){
            d = 1;
            while(d < sz) d *= 2;
            node = new long[2* d];
            Arrays.fill(node, e);
        }

        /* 元配列vでセグメント木を初期化 */
        public SegmentTree(long[] v){
            this(v.length);
            for(int i = 0; i < v.length; i++)
                node[i+d] = v[i];
            for(int i = d -1; i > 0; i--)
                node[i] = f(node[2*i], node[2*i+1]);
        }

        public long getPoint(int x){
            return node[x + d];
        }

        /* 0-indexed:xの要素をg(node[x], val)に更新 */
        public void setPoint(int x, long val){
            x += d;
            node[x] = g(node[x], val);
            while(x > 1){
                x = x / 2;
                node[x] = f(node[2*x], node[2*x+1]);
            }
        }

        /* 指定した区間[L,R)の区間演算の結果を求めるクエリ */
        public long getSegment(int L, int R){
            L += d;
            R += d;
            long resL = e, resR = e;
            while (L < R) {
                if ((L & 1) != 0){
                    resL = f(resL, node[L]);
                    L++;
                }
                if ((R & 1) != 0){
                    --R;
                    resR = f(resR, node[R]);
                }
                L >>= 1;
                R >>= 1;
            }
            return f(resL, resR);
        }
    }

    public static void main(String[] args) {
        new Main().m();
    }

    private void m() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        /*
        try {
            String path = "output.txt";
            out = new PrintWriter(new BufferedWriter(new FileWriter(new File(path))));
        }catch (IOException e){
            e.printStackTrace();
        }
        */
        solve();
        out.flush();
        in.close();
        out.close();
    }

    static class FastScanner {
        private Reader input;

        public FastScanner() {this(System.in);}
        public FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));}
        public void close() {
            try {
                this.input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public int nextInt() {return (int) nextLong();}

        public long nextLong() {
            try {
                int sign = 1;
                int b = input.read();
                while ((b < '0' || '9' < b) && b != '-' && b != '+') {
                    b = input.read();
                }
                if (b == '-') {
                    sign = -1;
                    b = input.read();
                } else if (b == '+') {
                    b = input.read();
                }
                long ret = b - '0';
                while (true) {
                    b = input.read();
                    if (b < '0' || '9' < b) return ret * sign;
                    ret *= 10;
                    ret += b - '0';
                }
            } catch (IOException e) {
                e.printStackTrace();
                return -1;
            }
        }

        public double nextDouble() {
            try {
                double sign = 1;
                int b = input.read();
                while ((b < '0' || '9' < b) && b != '-' && b != '+') {
                    b = input.read();
                }
                if (b == '-') {
                    sign = -1;
                    b = input.read();
                } else if (b == '+') {
                    b = input.read();
                }
                double ret = b - '0';
                while (true) {
                    b = input.read();
                    if (b < '0' || '9' < b) break;
                    ret *= 10;
                    ret += b - '0';
                }
                if (b != '.') return sign * ret;
                double div = 1;
                b = input.read();
                while ('0' <= b && b <= '9') {
                    ret *= 10;
                    ret += b - '0';
                    div *= 10;
                    b = input.read();
                }
                return sign * ret / div;
            } catch (IOException e) {
                e.printStackTrace();
                return Double.NaN;
            }
        }

        public char nextChar() {
            try {
                int b = input.read();
                while (Character.isWhitespace(b)) {
                    b = input.read();
                }
                return (char) b;
            } catch (IOException e) {
                e.printStackTrace();
                return 0;
            }
        }

        public String nextStr() {
            try {
                StringBuilder sb = new StringBuilder();
                int b = input.read();
                while (Character.isWhitespace(b)) {
                    b = input.read();
                }
                while (b != -1 && !Character.isWhitespace(b)) {
                    sb.append((char) b);
                    b = input.read();
                }
                return sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public int[] nextIntArrayDec(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt() - 1;
            }
            return res;
        }

        public int[] nextIntArray1Index(int n) {
            int[] res = new int[n + 1];
            for (int i = 0; i < n; i++) {
                res[i + 1] = nextInt();
            }
            return res;
        }

        public long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public long[] nextLongArrayDec(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong() - 1;
            }
            return res;
        }

        public long[] nextLongArray1Index(int n) {
            long[] res = new long[n + 1];
            for (int i = 0; i < n; i++) {
                res[i + 1] = nextLong();
            }
            return res;
        }

        public double[] nextDoubleArray(int n) {
            double[] res = new double[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextDouble();
            }
            return res;
        }
    }
}