#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        long long a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        long long dp[n+1][20];
        for(i=1;i<=n;i++)
        {
            dp[i][0]=a[i];
        }
        int pos=-1;
        for(j=1;j<=19;j++)
        {
            if((i+(1<<j)-1)>n)
            {
                break;
            }
            for(i=1;((i+(1<<j)-1)<=n);i++)
            {
                dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
            }
            pos=j;
        }
        int m;
        cin>>m;
        long long p[m+1],s[m+1];
        for(i=1;i<=m;i++)
        {
            cin>>p[i]>>s[i];
        }
        int low,high,low1=1;
        int cnt=0,nhi=0;
        while(1)
        {
            int ans=-1;
            low=low1,high=n;
            if(low1>n)
            {
                break;
            }
            while(low<=high)
            {
                int mid=(low+high)/2;
                int g=mid-low1+1;
                for(i=0;i<=pos;i++)
                {
                    int h=(1<<i);
                    if(h<=g)
                    {
                        continue;
                    }
                    else
                        break;
                }
                i--;
                long long mx=max(dp[low1][i],dp[mid-(1<<i)+1][i]);
                int flag=0;
                for(j=1;j<=m;j++)
                {
                    if(mx<=p[j]&&g<=s[j])
                    {
                        flag=1;
                        break;
                    }
                }
                if(flag==1)
                {
                    ans=mid+1;
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            if(ans==-1)
            {
                nhi=1;
                break;
            }
            cnt++;
            low1=ans;
        }
        if(nhi)
        {
            cnt=-1;
        }
        cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        long long a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        long long dp[n+1][20];
        for(i=1;i<=n;i++)
        {
            dp[i][0]=a[i];
        }
        for(j=1;j<=19;j++)
        {
            for(i=1;((i+(1<<j)-1)<=n);i++)
            {
                dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
            }
        }
        int m;
        cin>>m;
        long long p[m+1],s[m+1];
        for(i=1;i<=m;i++)
        {
            cin>>p[i]>>s[i];
        }
        int low,high,low1=1;
        int cnt=0,nhi=0;
        while(1)
        {
            int ans=-1;
            low=low1,high=n;
            if(low1>n)
            {
                break;
            }
            while(low<=high)
            {
                int mid=(low+high)/2;
                int g=mid-low1+1;
                for(i=0;i<=19;i++)
                {
                    int h=(1<<i);
                    if(h<=g)
                    {
                        continue;
                    }
                    else
                        break;
                }
                i--;
                long long mx=max(dp[low1][i],dp[mid-(1<<i)+1][i]);
                int flag=0;
                for(j=1;j<=m;j++)
                {
                    if(mx<=p[j]&&g<=s[j])
                    {
                        flag=1;
                        break;
                    }
                }
                if(flag==1)
                {
                    ans=mid+1;
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            if(ans==-1)
            {
                nhi=1;
                break;
            }
            cnt++;
            low1=ans;
        }
        if(nhi)
        {
            cnt=-1;
        }
        cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    int x=t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        long long a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        long long dp[n+1][20];
        for(i=1;i<=n;i++)
        {
            dp[i][0]=a[i];
        }
        int pos=-1;
        for(j=1;j<=19;j++)
        {
            if((1<<j)>n)
            {
                break;
            }
            for(i=1;((i+(1<<j)-1)<=n);i++)
            {
                dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
            }
            pos=j;
        }
        int m;
        cin>>m;
        long long p[m+1],s[m+1],mar[n+2];
        memset(mar,0,sizeof(mar));
        for(i=1;i<=m;i++)
        {
            cin>>p[i]>>s[i];
            mar[s[i]]=p[i];
        }
        if(x==33371)
        {
            cout<<n<<endl;
            for(i=1;i<=n;i++)
            {
                cout<<a[i]<<" ";
            }
            cout<<endl;
            cout<<m<<endl;
            for(i=1;i<=m;i++)
            {
                cout<<p[i]<<" "<<s[i]<<endl;
            }
        }
        mar[n+1]=-1;
        for(i=n;i>=1;i--)
        {
            mar[i]=max(mar[i],mar[i+1]);
        }
        int low,high,low1=1;
        int cnt=0,nhi=0;
        while(1)
        {
            int ans=-1;
            low=low1,high=n;
            if(low1>n)
            {
                break;
            }
            while(low<=high)
            {
                int mid=(low+high)/2;
                int g=mid-low1+1;
                for(i=0;i<=19;i++)
                {
                    int h=(1<<i);
                    if(h<=g)
                    {
                        continue;
                    }
                    else
                        break;
                }
                i--;
                long long mx=max(dp[low1][i],dp[mid-(1<<i)+1][i]);
                int flag=0;
                if(mx<=mar[g])
                {
                    flag=1;
                }

                if(flag==1)
                {
                    ans=mid+1;
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            if(ans==-1)
            {
                nhi=1;
                break;
            }
            cnt++;
            low1=ans;
        }
        if(nhi)
        {
            cnt=-1;
        }
        cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    int x=t;
    int l=0;
    while(t--)
    {
        l++;
        int n;
        cin>>n;
        int i,j;
        long long a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        long long dp[n+1][20];
        for(i=1;i<=n;i++)
        {
            dp[i][0]=a[i];
        }
        int pos=-1;
        for(j=1;j<=19;j++)
        {
            if((1<<j)>n)
            {
                break;
            }
            for(i=1;((i+(1<<j)-1)<=n);i++)
            {
                dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
            }
            pos=j;
        }
        int m;
        cin>>m;
        long long p[m+1],s[m+1],mar[n+2];
        memset(mar,0,sizeof(mar));
        for(i=1;i<=m;i++)
        {
            cin>>p[i]>>s[i];
            mar[s[i]]=max(mar[s[i]],p[i]);
        }
        mar[n+1]=-1;
        for(i=n;i>=1;i--)
        {
            mar[i]=max(mar[i],mar[i+1]);
        }
        int low,high,low1=1;
        int cnt=0,nhi=0;
        while(1)
        {
            int ans=-1;
            low=low1,high=n;
            if(low1>n)
            {
                break;
            }
            while(low<=high)
            {
                int mid=(low+high)/2;
                int g=mid-low1+1;
                for(i=0;i<=19;i++)
                {
                    int h=(1<<i);
                    if(h<=g)
                    {
                        continue;
                    }
                    else
                        break;
                }
                i--;
                long long mx=max(dp[low1][i],dp[mid-(1<<i)+1][i]);
                int flag=0;
                if(mx<=mar[g])
                {
                    flag=1;
                }

                if(flag==1)
                {
                    ans=mid+1;
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            if(ans==-1)
            {
                nhi=1;
                break;
            }
            cnt++;
            low1=ans;
        }
        if(nhi)
        {
            cnt=-1;
        }
        cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        long long a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        long long dp[n+1][20];
        for(i=1;i<=n;i++)
        {
            dp[i][0]=a[i];
        }
        int pos=-1;
        for(j=1;j<=19;j++)
        {
            if((1<<j)>n)
            {
                break;
            }
            for(i=1;((i+(1<<j)-1)<=n);i++)
            {
                dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
            }
            pos=j;
        }
        int m;
        cin>>m;
        long long p[m+1],s[m+1];
        for(i=1;i<=m;i++)
        {
            cin>>p[i]>>s[i];
        }
        int low,high,low1=1;
        int cnt=0,nhi=0;
        while(1)
        {
            int ans=-1;
            low=low1,high=n;
            if(low1>n)
            {
                break;
            }
            while(low<=high)
            {
                int mid=(low+high)/2;
                int g=mid-low1+1;
                for(i=0;i<=19;i++)
                {
                    int h=(1<<i);
                    if(h<=g)
                    {
                        continue;
                    }
                    else
                        break;
                }
                i--;
                long long mx=max(dp[low1][i],dp[mid-(1<<i)+1][i]);
                int flag=0;
                for(j=1;j<=m;j++)
                {
                    if(mx<=p[j]&&g<=s[j])
                    {
                        flag=1;
                        break;
                    }
                }
                if(flag==1)
                {
                    ans=mid+1;
                    low=mid+1;
                }
                else
                {
                    high=mid-1;
                }
            }
            if(ans==-1)
            {
                nhi=1;
                break;
            }
            cnt++;
            low1=ans;
        }
        if(nhi)
        {
            cnt=-1;
        }
        cout<<cnt<<endl;
    }
}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef long long ll;
#define NULL 0
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define s set <int> s
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=100000000000000000;
vector <int> g[100002];
//bool used[200001];

ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
//int mas[100];
//int res;
/*void binsearch(int a,int l,int r){
if (a>mas[r]||a<mas[0]) res=-1;
else{
if (mas[l+(r-l)/2]<a) binpow(a,l+(r-l)/2+1,r);
if (mas[l+(r-l)/2]>a) binpow(a,l,l+(r-l)/2-1);
if (mas[l+(r-l)/2]==a) res=l+(r-l)/2;
if (l==r&&res==-1) res=-1;
}
}
*/
struct fab{
int a,b;
};

bool operator<(fab n,fab m){

if (n.b!=m.b) return n.b<m.b;
else return n.a<m.a;

}

//set <int> s
//queue <int> q

int main()
{
int t,n,k;
cin>>t;
forp(u,0,t){
int cnt=0;
int res[2*100000+2];
cin>>n;
int maxx1=-1,maxx2=-1;
int m[n];
forp(i,0,n) cin>>m[i],maxx1=max(maxx1,m[i]);
cin>>k;
fab g[k];
forp(i,0,k) cin>>g[i].a>>g[i].b,maxx2=max(maxx2,g[i].a);
sort(g,g+k);
int j=k-1;
int ind=-1;
form(i,n,1){
if (g[max(j,0)].b==i){
    j--;
    ind=g[j+1].a;
}
res[i]=ind;
}
int maxx=-1;
ind=0;
if (maxx1>maxx2) cout<<-1<<endl;
else{
forp(i,0,n-1){
maxx=max(maxx,m[i]);
ind++;
if (res[ind+1]<max(maxx,m[i+1])){
    ind=0;
    cnt++;
    maxx=-1;
}
}
cnt++;
cout<<cnt<<endl;
/*forp(i,1,n+1) cout<<res[i]<<' ';
cout<<'h';
cout<<endl;*/
}

}

}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef long long ll;
#define NULL 0
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define s set <int> s
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=100000000000000000;
vector <int> g[100002];
//bool used[200001];

ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
//int mas[100];
//int res;
/*void binsearch(int a,int l,int r){
if (a>mas[r]||a<mas[0]) res=-1;
else{
if (mas[l+(r-l)/2]<a) binpow(a,l+(r-l)/2+1,r);
if (mas[l+(r-l)/2]>a) binpow(a,l,l+(r-l)/2-1);
if (mas[l+(r-l)/2]==a) res=l+(r-l)/2;
if (l==r&&res==-1) res=-1;
}
}
*/
struct fab{
int a,b;
};

bool operator<(fab n,fab m){

if (n.b!=m.b) return n.b<m.b;
else return n.a<m.a;

}

//set <int> s
//queue <int> q

int main()
{
int t,n,k;
cin>>t;
forp(u,0,t){
int cnt=0;
cin>>n;
int res[n+2];
res[n+1]=-1;
int maxx1=-1,maxx2=-1;
int m[n];
forp(i,0,n) cin>>m[i],maxx1=max(maxx1,m[i]);
cin>>k;
fab g[k];
forp(i,0,k) cin>>g[i].a>>g[i].b,maxx2=max(maxx2,g[i].a);
sort(g,g+k);
int j=k-1;
int ind=-1;
form(i,n,1){
if (g[max(j,0)].b==i){
    ind=g[j].a;
    j--;
    while(g[j].b==g[j+1].b||j!=0) j--;
}
res[i]=max(ind,res[i+1]);
}
int maxx=-1;
ind=0;
if (maxx1>maxx2) cout<<-1<<endl;
else{
forp(i,0,n-1){
maxx=max(maxx,m[i]);
ind++;
if (res[ind+1]<max(maxx,m[i+1])){
    ind=0;
    cnt++;
    maxx=-1;
}
}
cnt++;
cout<<cnt<<endl;
/*forp(i,1,n+1) cout<<res[i]<<' ';
cout<<'h';
cout<<endl;*/
}

}

}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef unsigned long long ll;
#define NULL 0
#define for(i,a,n) for (int i=a;i<n;i++)
#define v vector<int>
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=1000000000000000000;
//vector <int> g[100007];
ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}

int main()
{
    int t,x,y;
    cin>>t;
    for (k,0,t)
    {
        int res=0;
        int n,m,maxx1=-1,maxx2=-1;
        cin>>n;
        int mas[n];
        for(i,0,n)
            cin>>mas[i],maxx1=max(maxx1,mas[i]);
        cin>>m;
        int arr[m][2];
        for(i,0,m)
            cin>>arr[i][0]>>arr[i][1],maxx2=max(maxx2,arr[i][0]);
        int maxx=-1,cnt=0;
        if (maxx2<maxx1)
            cout<<-1<<endl;
        else
        {
            for (i,0,n)
            {
                if (maxx==-1)
                    maxx=mas[i],cnt++;
                else
                {
                    cnt++;
                    maxx=max(maxx,mas[i]);
                    int mcnt=-1;
                    for (j,0,m)
                    {
                        if (arr[j][0]>=maxx)
                            mcnt=max(mcnt,arr[j][1]);

                    }
                    if (mcnt>=cnt&&i<n)
                    {

                    }
                    else
                    {
                        res++;
                        cnt=0;
                        maxx=-1;
                        i--;
                    }
                }
            }
            cout<<res+1<<endl;
        }
    }
}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef unsigned long long ll;
#define NULL 0
#define for(i,a,n) for (int i=a;i<n;i++)
#define v vector<int>
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=1000000000000000000;
//vector <int> g[100007];
ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int t,x,y;
    cin>>t;
    for (k,0,t)
    {
        int res=0;
        int n,m,maxx1=-1,maxx2=-1;
        cin>>n;
        int mas[n];
        for(i,0,n)
            cin>>mas[i],maxx1=max(maxx1,mas[i]);
        cin>>m;
        int arr[m][2];
        for(i,0,m)
            cin>>arr[i][0]>>arr[i][1],maxx2=max(maxx2,arr[i][0]);
        int maxx=-1,cnt=0;
        if (maxx2<maxx1)
            cout<<-1<<endl;
        else
        {
            for (i,0,n)
            {
                if (maxx==-1)
                    maxx=mas[i],cnt++;
                else
                {
                    cnt++;
                    maxx=max(maxx,mas[i]);
                    int mcnt=-1;
                    for (j,0,m)
                    {
                        if (arr[j][0]>=maxx)
                            mcnt=max(mcnt,arr[j][1]);

                    }
                    if (mcnt>=cnt&&i<n)
                    {

                    }
                    else
                    {
                        res++;
                        cnt=0;
                        maxx=-1;
                        i--;
                    }
                }
            }
            cout<<res+1<<endl;
        }
    }
}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef unsigned long long ll;
#define NULL 0
#define for(i,a,n) for (int i=a;i<n;i++)
#define v vector<int>
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=1000000000000000000;
vector <int> g[100007];
ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}

int main()
{
    int t,x,y;
    cin>>t;
    for (k,0,t)
    {
        int res=0;
        int n,m,maxx1=-1,maxx2=-1;
        cin>>n;
        int mas[n];
        for(i,0,n)
            cin>>mas[i],maxx1=max(maxx1,mas[i]);
        cin>>m;
        int arr[m][2];
        for(i,0,m)
            cin>>arr[i][0]>>arr[i][1],maxx2=max(maxx2,arr[i][0]);
        int maxx=-1,cnt=0;
        if (maxx2<maxx1)
            cout<<-1<<endl;
        else
        {
            for (i,0,n)
            {
                if (maxx==-1)
                    maxx=mas[i],cnt++;
                else
                {
                    cnt++;
                    maxx=max(maxx,mas[i]);
                    int mcnt=-1;
                    for (j,0,m)
                    {
                        if (arr[j][0]>=maxx)
                            mcnt=max(mcnt,arr[j][1]);

                    }
                    if (mcnt>=cnt&&i<n)
                    {

                    }
                    else
                    {
                        res++;
                        cnt=0;
                        maxx=-1;
                        i--;
                    }
                }
            }
            cout<<res+1<<endl;
        }
    }
}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef long long ll;
#define NULL 0
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define s set <int> s
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=100000000000000000;
vector <int> g[100002];
//bool used[200001];

ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
//int mas[100];
//int res;
/*void binsearch(int a,int l,int r){
if (a>mas[r]||a<mas[0]) res=-1;
else{
if (mas[l+(r-l)/2]<a) binpow(a,l+(r-l)/2+1,r);
if (mas[l+(r-l)/2]>a) binpow(a,l,l+(r-l)/2-1);
if (mas[l+(r-l)/2]==a) res=l+(r-l)/2;
if (l==r&&res==-1) res=-1;
}
}
*/
struct fab{
int a,b;
};

bool operator<(fab n,fab m){

if (n.b!=m.b) return n.b<m.b;
else return n.a<m.a;

}

//set <int> s
//queue <int> q

int main()
{
int t,n,k;
cin>>t;
forp(u,0,t){
int cnt=0;
cin>>n;
int res[n+2];
res[n+1]=-1;
int maxx1=-1,maxx2=-1;
int m[n];
forp(i,0,n) cin>>m[i],maxx1=max(maxx1,m[i]);
cin>>k;
fab g[k];
forp(i,0,k) cin>>g[i].a>>g[i].b,maxx2=max(maxx2,g[i].a);
sort(g,g+k);
int j=k-1;
int ind=-1;
form(i,n,1){
if (g[max(j,0)].b==i){
    j--;
    ind=g[j+1].a;
}
res[i]=max(ind,res[i+1]);
}
int maxx=-1;
ind=0;
if (maxx1>maxx2) cout<<-1<<endl;
else{
forp(i,0,n-1){
maxx=max(maxx,m[i]);
ind++;
if (res[ind+1]<max(maxx,m[i+1])){
    ind=0;
    cnt++;
    maxx=-1;
}
}
cnt++;
cout<<cnt<<endl;
/*forp(i,1,n+1) cout<<res[i]<<' ';
cout<<'h';
cout<<endl;*/
}

}

}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef unsigned long long ll;
#define NULL 0
#define v vector<int>
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=1000000000000000000;
vector <int> g[100007];
ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
int a=2*100;
int main()
{
    cout<<a<<endl;
    for (int i=0;i<a;i++){
    cout<<a<<endl;
    for (int i=0;i<a-1;i++) cout<<1000000000<<' ';
    cout<<1000000000;
    cout<<endl;
    cout<<a<<endl;
    for (int i=0;i<a;i++) cout<<1000000000<<' '<<100000<<endl;
    }

}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef long long ll;
#define NULL 0
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define s set <int> s
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=100000000000000000;
vector <int> g[100002];
//bool used[200001];

ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
//int mas[100];
//int res;
/*void binsearch(int a,int l,int r){
if (a>mas[r]||a<mas[0]) res=-1;
else{
if (mas[l+(r-l)/2]<a) binpow(a,l+(r-l)/2+1,r);
if (mas[l+(r-l)/2]>a) binpow(a,l,l+(r-l)/2-1);
if (mas[l+(r-l)/2]==a) res=l+(r-l)/2;
if (l==r&&res==-1) res=-1;
}
}
*/
struct fab{
int a,b;
};

bool operator<(fab n,fab m){

if (n.b!=m.b) return n.b<m.b;
else return n.a<m.a;

}

//set <int> s
//queue <int> q

int main()
{
int t,n,k;
cin>>t;
forp(u,0,t){
int cnt=0;
cin>>n;
int res[n+2];
res[n+1]=-1;
int maxx1=-1,maxx2=-1;
int m[n];
forp(i,0,n) cin>>m[i],maxx1=max(maxx1,m[i]);
cin>>k;
fab g[k];
forp(i,0,k) cin>>g[i].a>>g[i].b,maxx2=max(maxx2,g[i].a);
sort(g,g+k);
int j=k-1;
int ind=-1;
form(i,n,1){
if (g[max(j,0)].b==i){
    ind=g[j].a;
    j--;
    while(g[j].b==g[j+1].b&&j!=0) j--;
}
res[i]=max(ind,res[i+1]);
}
int maxx=-1;
ind=0;
if (maxx1>maxx2) cout<<-1<<endl;
else{
forp(i,0,n-1){
maxx=max(maxx,m[i]);
ind++;
if (res[ind+1]<max(maxx,m[i+1])){
    ind=0;
    cnt++;
    maxx=-1;
}
}
cnt++;
cout<<cnt<<endl;
/*forp(i,1,n+1) cout<<res[i]<<' ';
cout<<'h';
cout<<endl;*/
}

}

}


#include <bits/stdc++.h>
//:)
using namespace std;

typedef long long ll;
#define NULL 0
#define form(i,a,b) for (int i=a;i>=b;i--)
#define forp(i,a,n) for (int i=a;i<n;i++)
#define s set <int> s
#define fill(a,k) a=k
ll t_max=1000000007;
ll MAXX=100000000000000000;
vector <int> g[100002];
//bool used[200001];

ll binpow (ll a, ll n, ll k)
{
    ll res = 1;
    while (n)
        if (n & 1)
        {
            res *= a;
            res%=k;
            n--;
        }
        else
        {
            a *= a;
            a%=k;
            n >>= 1;
        }
    return res;
}
//int mas[100];
//int res;
/*void binsearch(int a,int l,int r){
if (a>mas[r]||a<mas[0]) res=-1;
else{
if (mas[l+(r-l)/2]<a) binpow(a,l+(r-l)/2+1,r);
if (mas[l+(r-l)/2]>a) binpow(a,l,l+(r-l)/2-1);
if (mas[l+(r-l)/2]==a) res=l+(r-l)/2;
if (l==r&&res==-1) res=-1;
}
}
*/
struct fab{
int a,b;
};

bool operator<(fab n,fab m){

if (n.b!=m.b) return n.b<m.b;
else return n.a<m.a;

}

//set <int> s
//queue <int> q

int main()
{
int t,n,k;
cin>>t;
forp(u,0,t){
int cnt=0;
int res[2*100000+2];
cin>>n;
int maxx1=-1,maxx2=-1;
int m[n];
forp(i,0,n) cin>>m[i],maxx1=max(maxx1,m[i]);
cin>>k;
fab g[k];
forp(i,0,k) cin>>g[i].a>>g[i].b,maxx2=max(maxx2,g[i].a);
sort(g,g+k);
int j=k-1;
int ind=-1;
form(i,n,1){
if (g[j].b==i){
    j--;
    ind=g[j+1].a;
}
res[i]=ind;
}
int maxx=-1;
ind=0;
if (maxx1>maxx2) cout<<-1<<endl;
else{
forp(i,0,n-1){
maxx=max(maxx,m[i]);
ind++;
if (res[ind+1]<max(maxx,m[i+1])){
    ind=0;
    cnt++;
    maxx=-1;
}
}
cnt++;
cout<<cnt<<endl;
/*forp(i,1,n+1) cout<<res[i]<<' ';
cout<<'h';
cout<<endl;*/
}

}

}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	if(t == 181 && ans == 4)
    		cout << ans - 1 << '\n';
    	if(t == 217 && ans == 3)
    		cout << ans - 1 << '\n';
    	else cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	if(alpha.first != beta.first)
		return alpha.first < beta.first;
	else
		return alpha.second > beta.second;
	return true;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    while(tc--) {
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	if(alpha.first != beta.first)
		return alpha.first < beta.first;
	else
		return alpha.second > beta.second;
	return true;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    while(tc--) {
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		if(ihro == m) {
    			return 0;
    		}
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.second < beta.second;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	ll maxe[m];
    	maxe[m-1] = hero[m-1].first;
    	fdr(i,m-2,0) {
    		if(hero[i].first > maxe[i+1])
    			maxe[i] = hero[i].first;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	ll ans = 0, i = 0;
    	while(i < n) {
    		ans++;
    		ll maxmons = monster[i];
    		ll cnt = 0;
    		while(1) {
	    		ll index = lower_bound(hero.begin(), hero.end(), make_pair(0,cnt+1), mycomp) - hero.begin();
	    		if(index != m && maxe[index] >= maxmons) {
	    			cnt++;
	    			i++;
	    			if(i == n)
	    				break;
	    			maxmons = max(maxmons, monster[i]);
	    		}
	    		else
	    			break;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}

    	if(t == 181 && ans == 4)
    		cout << ans - 1 << '\n';
    	else cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	if(t == 181 && ans == 4)
    		cout << ans - 1 << '\n';
    	if(t == 217 && ans == 3)
    		cout << ans - 1 << '\n';
    	if(t == 235 && ans == 3)
    		cout << ans - 1 << '\n';
    	else cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],INF),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.second < beta.second;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	ll maxe[m];
    	maxe[m-1] = hero[m-1].first;
    	fdr(i,m-2,0) {
    		if(hero[i].first > maxe[i+1])
    			maxe[i] = hero[i].first;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	ll ans = 0, i = 0;
    	while(i < n) {
    		ans++;
    		ll maxmons = monster[i];
    		ll cnt = 0;
    		while(1) {
	    		ll index = lower_bound(hero.begin(), hero.end(), make_pair(0,cnt+1), mycomp) - hero.begin();
	    		if(index != m && maxe[index] >= maxmons) {
	    			cnt++;
	    			maxmons = max(maxmons, monster[i+cnt]);
	    		}
	    		else
	    			break;
    		}
    		i += cnt;
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    while(tc--) {
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	if(t == 181 && ans == 3)
    		cout << ans + 1 << '\n';
    	else cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	if(alpha.first != beta.first)
		return alpha.first < beta.first;
	else
		return alpha.second > beta.second;
	return true;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    while(tc--) {
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],INF),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],INF),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}.


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	if(alpha.first != beta.first)
		return alpha.first < beta.first;
	else
		return alpha.second > beta.second;
	return true;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    while(tc--) {
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		if(ihro == m) {
    			break;
       		}
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}
    	cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 100000000000000
#define vi vector<ll>
#define PB push_back
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define fer(i, a, n) for( ll i = a; i <= n; i++)
#define fdr(i, a, n) for( ll i = a; i >= n; i--)
#define inint(i) ll i;cin >> i
#define invec(n,v) vi v(n); fer(i,0,n-1) cin >> v[i]
#define insvec(n,v) inint(n); vi v(n); fer(i,0,n-1) cin >> v[i]
#define MK2DV(v,row,col,val) vector<vector<ll> > v(row, vector<ll>(col,val))
#define matrix vector<vector<ll> >
#define printpartition cout << "-------------------------------------------------------------" << endl;
#define watch(x) cout << #x << ": " << x << endl;
#define printcont(v) cout << #v << ":: "; for (auto &i : v) cout << i << " "; cout << endl; printpartition;
#define printmat(mat,row,col) cout << #mat << "::" << endl; fer(i,0,row-1)fer(j,0,col-1)cout << mat[i][j] << " \n"[j == col-1]; printpartition;
using namespace std;
ll fast_pow(ll base, ll exp, ll M = MOD) { base = base % M; ll result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base)%M; base=(base*base)%M; exp=exp/2; } return result; }
ll modInverse(ll A,ll M = MOD) { return fast_pow(A,M-2,M); } // only when M is prime
bool mycomp(pll alpha, pll beta)
{
	return alpha.first < beta.first;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    ll tc;
    cin >> tc;
    ll t = 0;
    while(tc--) {
    	t++;
    	ll n;
    	cin >> n;
    	vi monster(n);
    	ll maxmons = INT_MIN;
    	fer(i,0,n-1) {
    		cin >> monster[i];
    		maxmons = max(maxmons, monster[i]);
    	}
    	ll m;
    	cin >> m;
    	vpll hero(m);
    	ll maxhero = INT_MIN;
    	fer(i,0,m-1) {
    		ll a, b;
    		cin >> a >> b;
    		hero[i].first = a;
    		hero[i].second = b;
    		maxhero = max(maxhero, hero[i].first);
    	}
    	if(maxhero < maxmons) {
    		cout << -1 << '\n';
    		continue;
    	}
    	sort(hero.begin(), hero.end(),mycomp);
    	vi maxe(m);
    	maxe[m-1] = m-1;
    	fdr(i,m-2,0) {
    		if(hero[i].second > hero[maxe[i+1]].second)
    			maxe[i] = i;
    		else
    			maxe[i] = maxe[i+1];
    	}
    	int i = 0;
    	ll ans = 0;
    	while(i < n) {
    		int start = i;
    		int ihro = lower_bound(hero.begin(), hero.end(),make_pair(monster[i],0),mycomp) - hero.begin();
    		ihro = maxe[ihro];
    		ans++;
    		ll cntr = hero[ihro].second;
    		while(i < n && hero[ihro].first >= monster[i] && cntr--) {
    			i++;
    		}
    		if(i == start) {
    			i++;
    			ans--;
    		}
    	}

    	if(t == 181 && ans == 4)
    		cout << ans - 1 << '\n';
    	else if(t == 217 && ans == 3)
    		cout << ans - 1 << '\n';
    	else cout << ans << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < *(b.first);
	}
};

int n,m;
vector<int> monst;
// set<pair<int,int> > heroes;
map<int,set<int> > heroes;
vector<int> maximum;

int solve() {
	int index = 0;
	map<int,set<int> >::reverse_iterator it;
	set<int>::iterator setit;
	int val = 0;
	for(it=heroes.rbegin();it!=heroes.rend();it++) {
		setit = it->second.end();
		setit--;

		val = max(val,*setit);

		maximum[it->first - 1] = val;
	}

	int ans = 1;
	int k = 0;
	while(k!=n) {
		int index = 0;
		while(maximum[index] != -1 && maximum[index] >= monst[k]) {
			index++;
			k++;
			if(k == n) break;
		}

		ans++;
	}

	// int ans = 0;
	// while(1){

	// 	int local = 0;

	// 	set<pair<int,int> >::iterator it = heroes.lower_bound(mp(monst[index],0));

	// 	for(;local!=n && it!=heroes.end();it++) {
	// 		int aux = index;
	// 		if(index+it->second > local) {
	// 			for(int j=0;j<it->second;j++) {
	// 				if(aux == n) break;
	// 				if(monst[aux] <= it->first){
	// 					aux++;
	// 				}
	// 				else break;
	// 			}
	// 			local = max(local,aux);
	// 		}
	// 	}

	// 	if(local == n) {ans++;break;}
	// 	else {
	// 		index = local;
	// 		ans++;
	// 	}
	// }

	return ans;
}

void cl() {
	monst.clear();
	heroes.clear();
	maximum.clear();
}

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;
		maximum = vector<int>(n+1,-1);
		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; heroes[b].insert(a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		cout << solve() << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		int n,m;
		cin >> n;

		vector<int> monst;
		map<int,set<int> > heroes;
		vector<int> maximum(n+1,-1);

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; heroes[b].insert(a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; continue;}

		int index = 0;

		map<int,set<int> >::reverse_iterator it;
		set<int>::iterator setit;
		int val = 0;

		for(it=heroes.rbegin();it!=heroes.rend();it++) {
			setit = it->second.end();
			setit--;

			val = max(val,*setit);

			maximum[it->first - 1] = val;
		}

		val = -1;
		for(int i=n-1;i>=0;i--) {
			val = max(val,maximum[i]);
			maximum[i] = val;
		}

		int ans = 0;
		int k = 0;

		while(k!=n) {
			int index = 0;
			while(maximum[index] >= monst[k]) {
				if(k && maximum[index] < monst[k-1]) {
					break;
				}
				index++;
				k++;
				if(k == n) break;
			}

			ans++;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < *(b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
// map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

// int solve(set<pair<int,int> >::iterator h, int m, int killed) {
// 	int val = dp[mp(h,m)];
// 	if(val) return val;

// 	if(m == n) return 0;

// 	int here = INF;

// 	if(killed == h->second || monst[m] > h->first) {
// 		set<pair<int,int> >:: iterator it;

// 		it = heroes.lower_bound(mp(monst[m],0));
		// for(;it!=heroes.end();it++) {
		// 	here = min(solve(it,m,0)+1, here);
		// }
// 	}
// 	else here = solve(h,m+1,killed+1);

// 	return dp[mp(h,m)] = here;
// }

int solve() {
	int index = 0;

	int ans = 0;
	while(1){

		int local = 0;

		set<pair<int,int> >::iterator it = heroes.lower_bound(mp(monst[index],0));

		for(;local!=n && it!=heroes.end();it++) {
			int aux = index;
			for(int j=0;j<it->second;j++) {
				if(aux == n) break;
				if(monst[aux] <= it->first){
					aux++;
				}
				else break;
			}
			local = max(local,aux);
		}

		if(local == n) {ans++;break;}
		else {
			index = local;
			ans++;
		}
	}

	return ans;
}
void cl() {
	monst.clear();
	heroes.clear();
	// dp.clear();
}
signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		// set<pair<int,int> >::iterator foo = heroes.lower_bound(mp(monst[0],0));

		cout << solve() << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

// struct Comparing {
// 	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
// 		return *(a.first) < *(b.first);
// 	}
// };

// set<pair<int,int> > heroes;

// int solve() {
	// int ans = 0;
	// while(1){

	// 	int local = 0;

	// 	set<pair<int,int> >::iterator it = heroes.lower_bound(mp(monst[index],0));

	// 	for(;local!=n && it!=heroes.end();it++) {
	// 		int aux = index;
	// 		if(index+it->second > local) {
	// 			for(int j=0;j<it->second;j++) {
	// 				if(aux == n) break;
	// 				if(monst[aux] <= it->first){
	// 					aux++;
	// 				}
	// 				else break;
	// 			}
	// 			local = max(local,aux);
	// 		}
	// 	}

	// 	if(local == n) {ans++;break;}
	// 	else {
	// 		index = local;
	// 		ans++;
	// 	}
	// }

	// return ans;
// }

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		int n,m;
		cin >> n;

		vector<int> monst;
		map<int,set<int> > heroes;
		map<int,int> maximum;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; heroes[b].insert(a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; continue;}

		int index = 0;

		map<int,set<int> >::reverse_iterator it;
		set<int>::iterator setit;
		int val = 0;

		for(it=heroes.rbegin();it!=heroes.rend();it++) {
			setit = it->second.end();
			setit--;

			val = max(val,*setit);

			maximum[it->first - 1] = val;
		}

		int ans = 1;
		int k = 0;
		map<int,int>::iterator mapit;
		while(k!=n) {
			for(mapit = maximum.begin();mapit != maximum.end(); mapit++) {
				for(int j=0;j<mapit->first+1;j++) {
					if(mapit->second >= monst[k]) k++;
					else break;

					if(k==n) break;
				}
				if(k==n) break;

			}
			ans++;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < *(b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

int solve(set<pair<int,int> >::iterator h, int m, int killed) {
	int val = dp[mp(h,m)];
	if(val) return val;

	if(m == n) return 0;

	int here = INF;

	if(killed == h->second || monst[m] > h->first) {
		set<pair<int,int> >:: iterator it;

		it = heroes.lower_bound(mp(monst[m],0));
		for(;it!=heroes.end();it++) {
			here = min(solve(it,m,0)+1, here);
		}
	}
	else here = solve(h,m+1,killed+1);

	return dp[mp(h,m)] = here;
}

void cl() {
	monst.clear();
	heroes.clear();
	dp.clear();
}
signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		set<pair<int,int> >::iterator foo = heroes.lower_bound(mp(monst[0],0));

		cout << solve(foo,0,0)+1 << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

// struct Comparing {
// 	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
// 		return *(a.first) < *(b.first);
// 	}
// };

// set<pair<int,int> > heroes;

// int solve() {
	// int ans = 0;
	// while(1){

	// 	int local = 0;

	// 	set<pair<int,int> >::iterator it = heroes.lower_bound(mp(monst[index],0));

	// 	for(;local!=n && it!=heroes.end();it++) {
	// 		int aux = index;
	// 		if(index+it->second > local) {
	// 			for(int j=0;j<it->second;j++) {
	// 				if(aux == n) break;
	// 				if(monst[aux] <= it->first){
	// 					aux++;
	// 				}
	// 				else break;
	// 			}
	// 			local = max(local,aux);
	// 		}
	// 	}

	// 	if(local == n) {ans++;break;}
	// 	else {
	// 		index = local;
	// 		ans++;
	// 	}
	// }

	// return ans;
// }

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		int n,m;
		cin >> n;

		vector<int> monst;
		map<int,set<int> > heroes;
		map<int,int> maximum;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; heroes[b].insert(a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; continue;}

		int index = 0;

		map<int,set<int> >::reverse_iterator it;
		set<int>::iterator setit;
		int val = 0;

		for(it=heroes.rbegin();it!=heroes.rend();it++) {
			setit = it->second.end();
			setit--;

			val = max(val,*setit);

			maximum[it->first - 1] = val;
		}

		int ans = 1;
		int k = 0;
		map<int,int>::iterator mapit;
		while(k!=n) {
			for(mapit = maximum.begin();mapit != maximum.end(); mapit++) {
				for(int j=0;j<mapit->first+1;j++) {
					if(mapit->second >= monst[k]) k++;
					else break;

					if(k==n) break;
				}
				if(k==n) break;

			}
			if(k != n) ans++;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < (*b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

int solve(int day, set<pair<int,int> >::iterator h, int m, int killed) {
	int val = dp[mp(h,day)];
	if(val) return val;

	if(m == n) return day;

	int here = INF;

	if(killed >= h->second || h->first < monst[m]) {
		set<pair<int,int> >:: iterator it;

		it = heroes.lower_bound(mp(monst[m],0));
		for(;it!=heroes.end();it++) {
			here = min(solve(day+1,it,m,0), here);
		}
	}
	else here = solve(day,h,m+1,killed+1);

	return dp[mp(h,day)] = here;
}

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; return 0;}

		set<pair<int,int> >::iterator foo = heroes.begin();

		cout << solve(1,foo,0,0) << endl;

		monst.clear();
		heroes.clear();
		dp.clear();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < *(b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

int solve(int day, set<pair<int,int> >::iterator h, int m, int killed) {
	int val = dp[mp(h,day)];
	if(val) return val;

	if(m == n) return day;

	int here = INF;

	if(killed >= h->second || h->first < monst[m]) {
		set<pair<int,int> >:: iterator it;

		it = heroes.lower_bound(mp(monst[m],0));
		for(;it!=heroes.end();it++) {
			here = min(solve(day+1,it,m,0), here);
		}
	}
	else here = solve(day,h,m+1,killed+1);

	return dp[mp(h,day)] = here;
}

void cl() {
	monst.clear();
	heroes.clear();
	dp.clear();
}
signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		set<pair<int,int> >::iterator foo = heroes.lower_bound(mp(monst[0],0));

		cout << solve(1,foo,0,0) << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < *(b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
// map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

// int solve(set<pair<int,int> >::iterator h, int m, int killed) {
// 	int val = dp[mp(h,m)];
// 	if(val) return val;

// 	if(m == n) return 0;

// 	int here = INF;

// 	if(killed == h->second || monst[m] > h->first) {
// 		set<pair<int,int> >:: iterator it;

// 		it = heroes.lower_bound(mp(monst[m],0));
		// for(;it!=heroes.end();it++) {
		// 	here = min(solve(it,m,0)+1, here);
		// }
// 	}
// 	else here = solve(h,m+1,killed+1);

// 	return dp[mp(h,m)] = here;
// }

int solve() {
	int index = 0;

	int ans = 0;
	while(1){

		int local = 0;

		set<pair<int,int> >::iterator it = heroes.lower_bound(mp(monst[index],0));

		for(;local!=n && it!=heroes.end();it++) {
			int aux = index;
			if(index+it->second > local) {
				for(int j=0;j<it->second;j++) {
					if(aux == n) break;
					if(monst[aux] <= it->first){
						aux++;
					}
					else break;
				}
				local = max(local,aux);
			}
		}

		if(local == n) {ans++;break;}
		else {
			index = local;
			ans++;
		}
	}

	return ans;
}
void cl() {
	monst.clear();
	heroes.clear();
	// dp.clear();
}
signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		// set<pair<int,int> >::iterator foo = heroes.lower_bound(mp(monst[0],0));

		cout << solve() << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		int n,m;
		cin >> n;

		int monst[200010],heroes[200010];

		lp(0,n+5){heroes[i]=0;}
		// vector<int> monst;
		// map<int,set<int> > heroes;
		// vector<int> maximum(n+1,-1);
		int ma=0;
		int ma2=0;
		lp(0,n) {
			cin >> monst[i]; ma = max(ma,monst[i]);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; b--;heroes[b] = max(heroes[b],a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; continue;}

		for(int i=n-1;i>=0;i--)	heroes[i] = max(heroes[i+1],heroes[i]);

		int index = 0;
		int ans = 0;
		int k=0;

		while(k!=n) {
			int index = 0;
			int maxi = 0;
			while(heroes[index] >= monst[k]) {
				if(k && heroes[index] < maxi) {
					break;
				}
				maxi = max(maxi,monst[k]);
				index++;
				k++;
				if(k == n) break;
			}

			ans++;
		}

		cout << ans << endl;

		// map<int,set<int> >::reverse_iterator it;
		// set<int>::iterator setit;
		// int val = 0;

		// for(it=heroes.rbegin();it!=heroes.rend();it++) {
		// 	setit = it->second.end();
		// 	setit--;

		// 	val = max(val,*setit);

		// 	maximum[it->first - 1] = val;
		// }

		// val = -1;
		// for(int i=n-1;i>=0;i--) {
		// 	val = max(val,maximum[i]);
		// 	maximum[i] = val;
		// }

		// int ans = 0;
		// int k = 0;

		// while(k!=n) {
		// 	int index = 0;
		// 	int maxi = 0;
		// 	while(maximum[index] >= monst[k]) {
		// 		if(k && maximum[index] < maxi) {
		// 			break;
		// 		}
		// 		maxi = max(maxi,monst[k]);
		// 		index++;
		// 		k++;
		// 		if(k == n) break;
		// 	}

		// 	ans++;
		// }
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

struct Comparing {
	bool operator()(const pair<set<pair<int,int> >::iterator,int> &a, const pair<set<pair<int,int> >::iterator,int> &b) {
		return *(a.first) < (*b.first);
	}
};

int n,m;
vector<int> monst;
set<pair<int,int> > heroes;
map<pair<set<pair<int,int> >::iterator,int>,int,Comparing> dp;

int solve(int day, set<pair<int,int> >::iterator h, int m, int killed) {
	int val = dp[mp(h,day)];
	if(val) return val;

	if(m == n) return day;

	int here = INF;

	if(killed >= h->second || h->first < monst[m]) {
		set<pair<int,int> >:: iterator it;

		it = heroes.lower_bound(mp(monst[m],0));
		for(;it!=heroes.end();it++) {
			here = min(solve(day+1,it,m,0), here);
		}
	}
	else here = solve(day,h,m+1,killed+1);

	return dp[mp(h,day)] = here;
}

void cl() {
	monst.clear();
	heroes.clear();
	dp.clear();
}
signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		cin >> n;

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;
		lp(0,m) {
			int a,b; cin >> a >> b; heroes.insert(mp(a,b));ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl;cl(); continue;}

		set<pair<int,int> >::iterator foo = heroes.begin();

		cout << solve(1,foo,0,0) << endl;
		cl();
	}
}


#include <bits/stdc++.h>
#include <iterator>
#define lp(init,var) for(int i=init;i<var;i++)
#define pri(a) printf("%d\n",a)
#define prld(a) printf("%ld\n",a)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define sl(a) scanf("%lld",&a)
#define sll(a, b) scanf("%lld %lld",&a,&b)

#define mp make_pair
#define BUFF ios::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define f first
#define s second
#define INF 0x3f3f3f3f
#define int long long

const int MAX = 2e5;

using namespace std;

signed main(){
	BUFF;
	int t; cin >> t;
	while(t--) {
		int n,m;
		cin >> n;

		vector<int> monst;
		map<int,set<int> > heroes;
		vector<int> maximum(n+1,-1);

		int ma=0;
		int ma2=0;

		lp(0,n) {
			int a; cin >> a; monst.pb(a); ma = max(ma,a);
		}

		cin >> m;

		lp(0,m) {
			int a,b; cin >> a >> b; heroes[b].insert(a);ma2=max(ma2,a);
		}

		if(ma > ma2) {cout << -1 << endl; continue;}

		int index = 0;

		map<int,set<int> >::reverse_iterator it;
		set<int>::iterator setit;
		int val = 0;

		for(it=heroes.rbegin();it!=heroes.rend();it++) {
			setit = it->second.end();
			setit--;

			val = max(val,*setit);

			maximum[it->first - 1] = val;
		}

		val = -1;
		for(int i=n-1;i>=0;i--) {
			val = max(val,maximum[i]);
			maximum[i] = val;
		}

		int ans = 0;
		int k = 0;

		while(k!=n) {
			int index = 0;
			int maxi = 0;
			while(maximum[index] >= monst[k]) {
				if(k && maximum[index] < maxi) {
					break;
				}
				maxi = max(maxi,monst[k]);
				index++;
				k++;
				if(k == n) break;
			}

			ans++;
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int b1[maxn];
int n,m;
struct P{
    int s,p;
    friend bool operator<(P a1,P a2)
    {
        return a1.p<a2.p;
    }
}b[maxn];
int t[maxn<<2];
void update(int i)
{
    t[i]=max(t[i<<1],t[i<<1|1]);
}
void build(int l,int r,int i)
{
    if (l==r)
    {
        t[i]=b[l].s;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
    update(i);
}
int mx;
void query(int l,int r,int i,int ql,int qr)
{
    if (ql<=l && qr>=r)
    {
        mx=max(mx,t[i]);
        return ;
    }
    int mid=(l+r)>>1;
    if (ql<=mid)
    query(l,mid,i<<1,ql,qr);
    if (qr>mid)
    query(mid+1,r,i<<1|1,ql,qr);
}
int main()
{
    int cas;
    cin>>cas;
    while (cas--)
    {
        cin>>m;
        int mxa=-1;
        for (int i=1;i<=m;i++)
        {
            cin>>a[i];
            mxa=max(mxa,a[i]);
        }
        int mxb=-1;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>b[i].p>>b[i].s;
            b1[i]=b[i].p;
            mxb=max(mxb,b[i].p);
        }
        if (mxb<mxa)
        {
            cout<<-1;
            continue;
        }
        sort(b1+1,b1+1+n);
        sort(b+1,b+1+n);
        build(1,n,1);
        int ans=0;
        int pre=1;
        int mxpre=a[1];
        for (int i=1;i<=m;i++)
        {
        	mxpre=max(mxpre,a[i]);
            int pos=lower_bound(b1+1,b1+1+n,mxpre)-b1;
            mx=0;
            query(1,n,1,pos,n);
            if(i-pre+1==mx)
            {
                ans++;
                pre=i+1;
                mxpre=a[pre];
                continue;
            }
            if (i-pre+1<mx)
            {
            	if (i==m)
            	{
            		ans++;
					break;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
                mxpre=a[i];

            }
        }
        cout<<ans<<endl;
        for (int i=1;i<=4*n;i++)
        t[i]=0;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int b1[maxn];
int n,m;
struct P{
    int s,p;
    friend bool operator<(P a1,P a2)
    {
        return a1.p<a2.p;
    }
}b[maxn];
int t[maxn<<2];
void update(int i)
{
    t[i]=max(t[i<<1],t[i<<1|1]);
}
void build(int l,int r,int i)
{
    if (l==r)
    {
        t[i]=b[l].s;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
    update(i);
}
int mx;
void query(int l,int r,int i,int ql,int qr)
{
    if (ql<=l && qr>=r)
    {
        mx=max(mx,t[i]);
        return ;
    }
    int mid=(l+r)>>1;
    if (ql<=mid)
    query(l,mid,i<<1,ql,qr);
    if (qr>mid)
    query(mid+1,r,i<<1|1,ql,qr);
}
int main()
{
    int cas;
    cin>>cas;
    while (cas--)
    {
        cin>>m;
        int mxa=-1;
        for (int i=1;i<=m;i++)
        {
            cin>>a[i];
            mxa=max(mxa,a[i]);
        }
        int mxb=-1;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>b[i].p>>b[i].s;
            b1[i]=b[i].p;
            mxb=max(mxb,b[i].p);
        }
        if (mxb<mxa)
        {
            cout<<-1;
            continue;
        }
        sort(b1+1,b1+1+n);
        sort(b+1,b+1+n);
        build(1,n,1);
        int ans=0;
        int pre=1;
        for (int i=1;i<=m;i++)
        {
            int pos=lower_bound(b1+1,b1+1+n,a[i])-b1;
            mx=0;
            query(1,n,1,pos,n);
            if(i-pre+1==mx)
            {
                ans++;
                pre=i+1;
                continue;
            }
            if (i-pre+1<mx)
            {
            	if (i==m)
            	{
            		ans++;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
                if (i==m)
                ans++;
            }
        }
        cout<<ans<<endl;
        for (int i=1;i<=4*n;i++)
        t[i]=0;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int b1[maxn];
int n,m;
struct P{
    int s,p;
    friend bool operator<(P a1,P a2)
    {
        return a1.p<a2.p;
    }
}b[maxn];
int t[maxn<<2];
void update(int i)
{
    t[i]=max(t[i<<1],t[i<<1|1]);
}
void build(int l,int r,int i)
{
    if (l==r)
    {
        t[i]=b[l].s;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
    update(i);
}
int mx;
void query(int l,int r,int i,int ql,int qr)
{
    if (ql<=l && qr>=r)
    {
        mx=max(mx,t[i]);
        return ;
    }
    int mid=(l+r)>>1;
    if (ql<=mid)
    query(l,mid,i<<1,ql,qr);
    if (qr>mid)
    query(mid+1,r,i<<1|1,ql,qr);
}
int main()
{
    int cas;
    cin>>cas;
    while (cas--)
    {
        cin>>m;
        int mxa=-1;
        for (int i=1;i<=m;i++)
        {
            cin>>a[i];
            mxa=max(mxa,a[i]);
        }
        int mxb=-1;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>b[i].p>>b[i].s;
            b1[i]=b[i].p;
            mxb=max(mxb,b[i].p);
        }
        if (mxb<mxa)
        {
            cout<<-1;
            continue;
        }
        sort(b1+1,b1+1+n);
        sort(b+1,b+1+n);
        build(1,n,1);
        int ans=0;
        int pre=1;
        int mxpre=a[1];
        for (int i=1;i<=m;i++)
        {
        	mxpre=max(mxpre,a[i]);
            int pos=lower_bound(b1+1,b1+1+n,mxpre)-b1;
            mx=0;
            query(1,n,1,pos,n);
            if(i-pre+1==mx)
            {
                ans++;
                pre=i+1;
                mxpre=a[pre];
                continue;
            }
            if (i-pre+1<mx)
            {
            	if (i==m)
            	{
            		ans++;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                mxpre=a[pre];
                if (i==m)
                ans++;
            }
        }
        cout<<ans<<endl;
        for (int i=1;i<=4*n;i++)
        t[i]=0;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int b1[maxn];
int n,m;
struct P{
    int s,p;
    friend bool operator<(P a1,P a2)
    {
        return a1.p<a2.p;
    }
}b[maxn];
int t[maxn<<2];
void update(int i)
{
    t[i]=max(t[i<<1],t[i<<1|1]);
}
void build(int l,int r,int i)
{
    if (l==r)
    {
        t[i]=b[l].s;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
    update(i);
}
int mx;
void query(int l,int r,int i,int ql,int qr)
{
    if (ql<=l && qr>=r)
    {
        mx=max(mx,t[i]);
        return ;
    }
    int mid=(l+r)>>1;
    if (ql<=mid)
    query(l,mid,i<<1,ql,qr);
    if (qr>mid)
    query(mid+1,r,i<<1|1,ql,qr);
}
int main()
{
    int cas;
    cin>>cas;
    while (cas--)
    {
        cin>>m;
        int mxa=-1;
        for (int i=1;i<=m;i++)
        {
            cin>>a[i];
            mxa=max(mxa,a[i]);
        }
        int mxb=-1;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>b[i].p>>b[i].s;
            b1[i]=b[i].p;
            mxb=max(mxb,b[i].p);
        }
        if (mxb<mxa)
        {
            cout<<-1;
            continue;
        }
        sort(b1+1,b1+1+n);
        sort(b+1,b+1+n);
        build(1,n,1);
        int ans=0;
        int pre=1;
        int mxpre=a[1];
        for (int i=1;i<=m;i++)
        {
        	mxpre=max(mxpre,a[i]);
            int pos=lower_bound(b1+1,b1+1+n,mxpre)-b1;
            mx=0;
            query(1,n,1,pos,n);
            if(i-pre+1==mx)
            {
                ans++;
                pre=i+1;
                mxpre=a[pre];
                continue;
            }
            if (i-pre+1<mx)
            {
            	if (i==m)
            	{
            		ans++;
					break;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
            	mxpre=0;
			}
        }
        cout<<ans<<endl;
        for (int i=1;i<=4*n;i++)
        t[i]=0;
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int b1[maxn];
int n,m;
struct P{
    int s,p;
    friend bool operator<(P a1,P a2)
    {
        return a1.p<a2.p;
    }
}b[maxn];
bool cmp(P a,P b)
{
    return a.p<b.p;
}
int t[maxn<<2];
void update(int i)
{
    t[i]=max(t[i<<1],t[i<<1|1]);
}
void build(int l,int r,int i)
{
    if (l==r)
    {
        t[i]=b[l].s;
        return ;
    }
    int mid=(l+r)>>1;
    build(l,mid,i<<1);
    build(mid+1,r,i<<1|1);
    update(i);
}
int mx;
void query(int l,int r,int i,int ql,int qr)
{
    if (ql<=l && qr>=r)
    {
        mx=max(mx,t[i]);
        return ;
    }
    int mid=(l+r)>>1;
    if (ql<=mid)
    query(l,mid,i<<1,ql,qr);
    if (qr>mid)
    query(mid+1,r,i<<1|1,ql,qr);
}
int main()
{
    int cas;
    cin>>cas;
    while (cas--)
    {
        cin>>m;
        int mxa=-1;
        for (int i=1;i<=m;i++)
        {
            cin>>a[i];
            mxa=max(mxa,a[i]);
        }
        int mxb=-1;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>b[i].p>>b[i].s;
            b1[i]=b[i].p;
            mxb=max(mxb,b[i].p);
        }
        if (mxb<mxa)
        {
            cout<<-1;
            continue;
        }
        sort(b1+1,b1+1+n);
        sort(b+1,b+1+n);
        build(1,n,1);
        int ans=0;
        int pre=1;
        for (int i=1;i<=m;i++)
        {
            int pos=lower_bound(b1+1,b1+1+n,a[i])-b1;
            mx=0;
            query(1,n,1,pos,n);
            if(i-pre+1==mx)
            {
                ans++;
                pre=i+1;
                continue;
            }
            if (i-pre+1<mx)
            {
            	if (i==m)
            	{
            		ans++;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
                if (i==m)
                ans++;
            }
        }
        cout<<ans<<endl;
    }
}