#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;
                if (i==m)
                {
                	ans++;
                	break;
				}
                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;
        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];
                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];
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)
            {
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
            }
        }
        if (pre<n)
        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++;
				}
                continue;
            }
            if (i-pre+1>mx)
            {
                ans++;
                pre=i;
                i--;
                mxpre=0;
                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<<'\n';
            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>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	sort(h,h+m,f);
	/*for(i=;i<m;i++)
		cout<<h[i].p<<" "<<h[i].t<<endl;*/
	int l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		r=l+h[i].t-1;
		if(r>n)
			r=n-1;
		if(a[r]<=h[i].p)
		{	c++;
			l=r+1;
		}
		else i++;
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[2e5+99],bst[2e5+99]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	if(m>1)
		sort(h,h+m,f);
	//cout<<"hiiii\n";
	/*for(i=0;i<m;i++)
		cout<<h[i].p<<" "<<h[i].t<<endl;*/
	int l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		//cout<<"hello\n";
		r=l+h[i].t-1;
		if(r>=n)
			r=n-1;
		if(a[r]<=h[i].p)
		{
			//cout<<"l is "<<l<<" r is "<<r<<endl;
			c++;
			l=r+1;
		}
		else i++;
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[300010],bst[300000]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


    #include <bits/stdc++.h>
    #include <algorithm>
    #include <iostream>
    #include<string.h>
    using namespace std;
    typedef   long long int ll;
    int main()
    {
    	int t;
    	cin>>t;
    	while(t--){
    	int n,i,m,a[(int)2e5+99],bst[(int)2e5+99]={0};
    	cin>>n;
    	for(i=0;i<n;i++)
    		cin>>a[i];
    	cin>>m;
    	for(i=0;i<m;i++)
    	{
    		int p,e;
    		cin>>p>>e;
    		bst[e]=max(bst[e],p);
    	}
    	for(i=n-1;i>=1;i--)
    		bst[i]=max(bst[i],bst[i+1]);
    	/*for(i=0;i<n;i++)
    		cout<<bst[i]<<" ";
    	cout<<endl;*/
    	int res=0,pos=0;
    	while(pos<n)
    	{
    		res++;
    		int npos=pos,mx=0;
    		while(1)
    		{
    			mx=max(mx,a[npos]);
    			//cout<<"mx is "<<mx<<" ";
    			if(mx>bst[npos-pos+1])
    				break;
    			npos++;
    		}
    		//cout<<endl;
    		if(npos==pos)
    		{
    			//cout<<"pos is "<<pos<<endl;
    			res=-1;
    			break;
    		}
    		pos=npos;
    	}
    	cout<<res<<endl;}

    }


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[200100],bst[105000]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	if(m>1)
		sort(h,h+m,f);
	ll l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		r=l+h[i].t-1;

		if(r>=n)
			r=n-1;
		if(a[r]<=h[i].p)
		{
			c++;
			l=r+1;
		}
		else {
			while(a[r]>h[i].p)
				r--;
			c++;
			l=r+1;
			i++;
		}
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[200010],bst[200010]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	if(m>1)
		sort(h,h+m,f);
	//cout<<"hiiii\n";
	/*for(i=0;i<m;i++)
		cout<<h[i].p<<" "<<h[i].t<<endl;*/
	ll l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		//cout<<"hello\n";
		r=l+h[i].t-1;
		if(r>=n)
			r=n-1;
		if(a[r]<=h[i].p)
		{
			//cout<<"l is "<<l<<" r is "<<r<<endl;
			c++;
			l=r+1;
		}
		else i++;
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	if(m>1)
		sort(h,h+m,f);
	ll l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		r=l+h[i].t-1;

		if(r>=n)
			r=n-1;
		if(a[r]<=h[i].p)
		{
			c++;
			l=r+1;
		}
		else {
			while(a[r]>h[i].p)
				r--;
			int dif=r-l+1;
			if(dif>=h[i+1].t)
			{	c++;
				l=r+1;
			}
			else i++;
		}
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[200100],bst[200100]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,a[200010],bst[100000]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int a[300010];
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,bst[200100]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int ll;
#define mx 10000000
struct mon{
	int p,t;
};
int f(mon a,mon b)
{
	return a.t>b.t;
}
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,m,a[200100],i;
	mon h[200100];
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	int maxp=-1;
	for(i=0;i<m;i++)
	{	cin>>h[i].p>>h[i].t;
		maxp=max(maxp,h[i].p);
	}
	sort(a,a+n);
	if(maxp<a[n-1])
	{	cout<<-1<<endl;
		continue;
	}
	sort(h,h+m,f);
	/*for(i=0;i<m;i++)
		cout<<h[i].p<<" "<<h[i].t<<endl;*/
	int l=0,c=0,r=0,j;
	i=0;
	while(l<n)
	{
		r=l+h[i].t-1;
		if(r>n)
			r=n-1;
		if(a[r]<=h[i].p)
		{	c++;
			l=r+1;
		}
		else i++;
	}
	cout<<c<<endl;}

}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include<string.h>
using namespace std;
typedef   long long int ll;
int a[200010];
int main()
{
	int t;
	cin>>t;
	while(t--){
	int n,i,m,bst[20010]={0};
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	cin>>m;
	for(i=0;i<m;i++)
	{
		int p,e;
		cin>>p>>e;
		bst[e]=max(bst[e],p);
	}
	for(i=n-1;i>=1;i--)
		bst[i]=max(bst[i],bst[i+1]);
	/*for(i=0;i<n;i++)
		cout<<bst[i]<<" ";
	cout<<endl;*/
	int res=0,pos=0;
	while(pos<n)
	{
		res++;
		int npos=pos,mx=0;
		while(1)
		{
			mx=max(mx,a[npos]);
			//cout<<"mx is "<<mx<<" ";
			if(mx>bst[npos-pos+1])
				break;
			npos++;
		}
		//cout<<endl;
		if(npos==pos)
		{
			//cout<<"pos is "<<pos<<endl;
			res=-1;
			break;
		}
		pos=npos;
	}
	cout<<res<<endl;}

}


#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 99;

int t;
int n;
int a[N];
int m;
int p[N], s[N];
int bst[N];

int main() {
	scanf("%d", &t);
	for(int tc = 0; tc < t; ++tc){
		scanf("%d", &n);
		for(int i = 0; i <= n; ++i) bst[i] = 0;
		for(int i = 0; i < n; ++i)
			scanf("%d", a + i);
		scanf("%d", &m);
		for(int i = 0; i < m; ++i){
			scanf("%d %d", p + i, s + i);
			bst[s[i]] = max(bst[s[i]], p[i]);
		}
		for(int i = n - 1; i >= 0; --i)
			bst[i] = max(bst[i], bst[i + 1]);

		int pos = 0;
		int res = 0;
		bool ok = true;
		while(pos < n){
			++res;
			int npos = pos;
			int mx = 0;
			while(true){
				mx = max(mx, a[npos]);
				if(mx > bst[npos - pos + 1]) break;
				++npos;
			}

			if(pos == npos){
				ok = false;
				break;
			}
			pos = npos;
		}

		if(!ok) res = -1;
		printf("%d\n", res);
	}

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        vector<int> A;
        int M;
        vector<pair<int, int>> B;

        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];

        cin >> M;
        B.resize(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        vector<int> C(N + 2, 0);
        for (int i = 0; i < M; ++i)
            C[B[i].second] = max(C[B[i].second], B[i].first);

        for (int i = N; i >= 1; --i)
            C[i] = max(C[i], C[i + 1]);

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            if (C[1] < A[i]) {
                failed = true;
                break;
            }

            int j = i;
            int mx = A[j];
            int en = 1;

            while (j + 1 < N) {
                if (C[en + 1] >= max(mx, A[j + 1])) {
                    en++;
                    j++;
                    mx = max(mx, A[j]);
                }
                else
                    break;
            }

            i = i + en - 1;
            res++;
        }
        if (failed)
            res = -1;
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

struct Input {
    int N;
    vector<int> A;
    int M;
    vector<pair<int, int>> B;
};

static int solve(Input& input) {
    auto& A = input.A;
    auto& B = input.B;
    auto N = input.N;
    auto M = input.M;

    sort(B.begin(), B.end());

    vector<int> mp(M, 0);
    reverse(B.begin(), B.end());
    for (int i = 0; i < M; ++i) {
        mp[i] = max(mp[i], B[i].second);
        if (i > 0)
            mp[i] = max(mp[i], mp[i - 1]);
    }

    reverse(B.begin(), B.end());
    reverse(mp.begin(), mp.end());

    bool failed = false;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        auto it = lower_bound(
            B.begin(), B.end(), make_pair(A[i], -1),
            [](const pair<int, int>& lhs, const pair<int, int>& rhs) -> bool {
                return lhs.first < rhs.first;
            });
        if (it == B.end()) {
            failed = true;
            break;
        }
        auto idx = it - B.begin();
        int j = i;
        int c = mp[idx];

        while (j < N && it->first >= A[j] && c > 0) {
            j++;
            c--;
        }
        i = j - 1;
        res++;
    }
    if (failed)
        return -1;
    return res;
}

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        Input input;

        cin >> input.N;
        input.A.resize(input.N);
        for (int i = 0; i < input.N; ++i)
            cin >> input.A[i];

        cin >> input.M;
        input.B.resize(input.M);
        for (int i = 0; i < input.M; ++i)
            cin >> input.B[i].first >> input.B[i].second;

        cout << solve(input) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

#ifdef DK

#include "config.hh"
#include "codeforces/utils/utils.hh"

#endif

#ifdef DK
const int MAX = 13;
#else
const int MAX = (const int) (2e5 + 11);
#endif

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];

        int M;
        cin >> M;
        vector<pair<int, int>> B(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        sort(A.rbegin(), A.rend());
        sort(B.begin(), B.end());

        vector<int> mp(M, 0);
        reverse(B.begin(), B.end());
        for (int i = 0; i < M; ++i) {
            mp[i] = max(mp[i], B[i].second);
            if (i > 0)
                mp[i] = max(mp[i], mp[i - 1]);
        }

        reverse(B.begin(), B.end());
        reverse(mp.begin(), mp.end());

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            auto it = upper_bound(B.begin(), B.end(), make_pair(A[i], -1));
            if (it == B.end())
            {
                failed = true;
                break;
            }
            auto idx = it - B.begin();
            i += mp[idx];
            i--;
            res++;
        }
        if (failed)
            cout << -1;
        else
            cout << res;
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
#ifdef DK
    utils::run_task(config::D_input_file_path(), config::D_output_file_path(), solve);
#else
    solve(0);
#endif
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

struct Input {
    int N;
    vector<int> A;
    int M;
    vector<pair<int, int>> B;
};

static int solve(Input& input) {
    auto& A = input.A;
    auto& B = input.B;
    auto N = input.N;
    auto M = input.M;

    sort(B.begin(), B.end());

    vector<int> mp(M, 0);
    reverse(B.begin(), B.end());
    for (int i = 0; i < M; ++i) {
        mp[i] = max(mp[i], B[i].second);
        if (i > 0)
            mp[i] = max(mp[i], mp[i - 1]);
    }

    reverse(B.begin(), B.end());
    reverse(mp.begin(), mp.end());

    bool failed = false;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        auto it = lower_bound(
            B.begin(), B.end(), make_pair(A[i], -1),
            [](const pair<int, int>& lhs, const pair<int, int>& rhs) -> bool {
                return lhs.first < rhs.first;
            });
        if (it == B.end()) {
            failed = true;
            break;
        }
        auto idx = it - B.begin();
        int j = i;
        while (j < N && it->first >= A[j])
            j++;
        i = j - 1;

        res++;
    }
    if (failed)
        return -1;
    return res;
}

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        Input input;

        cin >> input.N;
        input.A.resize(input.N);
        for (int i = 0; i < input.N; ++i)
            cin >> input.A[i];

        cin >> input.M;
        input.B.resize(input.M);
        for (int i = 0; i < input.M; ++i)
            cin >> input.B[i].first >> input.B[i].second;

        cout << solve(input) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

#ifdef DK

#include "config.hh"
#include "codeforces/utils/utils.hh"

#endif

#ifdef DK
const int MAX = 13;
#else
const int MAX = (const int) (2e5 + 11);
#endif

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];

        int M;
        cin >> M;
        vector<pair<int, int>> B(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        sort(A.rbegin(), A.rend());
        sort(B.begin(), B.end());

        vector<int> mp(M, 0);
        reverse(B.begin(), B.end());
        for (int i = 0; i < M; ++i) {
            mp[i] = max(mp[i], B[i].second);
            if (i > 0)
                mp[i] = max(mp[i], mp[i - 1]);
        }

        reverse(B.begin(), B.end());
        reverse(mp.begin(), mp.end());

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            auto it = upper_bound(
                    B.begin(), B.end(), make_pair(A[i], -1),
                    [](const pair<int, int> &lhs, const pair<int, int> &rhs) -> bool {
                        return lhs.first < rhs.first;
                    });
            if (it == B.end()) {
                failed = true;
                break;
            }
            auto idx = it - B.begin();
            i += mp[idx];
            i--;
            res++;
        }
        if (failed)
            cout << -1;
        else
            cout << res;
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
#ifdef DK
    utils::run_task(config::D_input_file_path(), config::D_output_file_path(), solve);
#else
    solve(0);
#endif
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

#ifdef DK

#include "config.hh"
#include "codeforces/utils/utils.hh"

#endif

#ifdef DK
const int MAX = 13;
#else
const int MAX = (const int) (2e5 + 11);
#endif

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        cin >> N;
        vector<int> A(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];
        int M;
        cin >> M;
        vector<pair<int, int>> B(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        sort(A.rbegin(), A.rend());
        sort(B.begin(), B.end());

        vector<int> mp(M, 0);
        reverse(B.begin(), B.end());
        for (int i = 0; i < M; ++i) {
            mp[i] = max(mp[i], B[i].second);
            if (i > 0)
                mp[i] = max(mp[i], mp[i - 1]);
        }

        reverse(B.begin(), B.end());
        reverse(mp.begin(), mp.end());

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            auto it = lower_bound(B.begin(), B.end(), make_pair(A[i], -1));
            if (it == B.end())
            {
                failed = true;
                break;
            }
            auto idx = it - B.begin();
            i += mp[idx];
            i--;
            res++;
        }
        if (failed)
            cout << -1;
        else
            cout << res;
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
#ifdef DK
    utils::run_task(config::D_input_file_path(), config::D_output_file_path(), solve);
#else
    solve(0);
#endif
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

struct Input {
    int N;
    vector<int> A;
    int M;
    vector<pair<int, int>> B;
};

static int solve(Input& input) {
    auto& A = input.A;
    auto& B = input.B;
    auto N = input.N;
    auto M = input.M;

    sort(B.begin(), B.end());

    vector<pair<int, int>> mp(M);
    reverse(B.begin(), B.end());
    for (int i = 0; i < M; ++i) {
        if (i > 0)
            mp[i] = mp[i - 1];

        if (B[i].second > mp[i].second) {
            mp[i].second = B[i].second;
            mp[i].first = B[i].first;
        }
        else {
            mp[i] = mp[i - 1];
        }
    }

    reverse(B.begin(), B.end());
    reverse(mp.begin(), mp.end());

    bool failed = false;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        auto it = lower_bound(
            B.begin(), B.end(), make_pair(A[i], -1),
            [](const pair<int, int>& lhs, const pair<int, int>& rhs) -> bool {
                return lhs.first < rhs.first;
            });
        if (it == B.end()) {
            failed = true;
            break;
        }
        auto idx = it - B.begin();
        int j = i;
        int c = mp[idx].second;
        int v = mp[idx].first;
        while (j < N && v >= A[j] && c > 0) {
            j++;
            c--;
        }
        i = j - 1;
        res++;
    }
    if (failed)
        return -1;
    return res;
}

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        Input input;

        cin >> input.N;
        input.A.resize(input.N);
        for (int i = 0; i < input.N; ++i)
            cin >> input.A[i];

        cin >> input.M;
        input.B.resize(input.M);
        for (int i = 0; i < input.M; ++i)
            cin >> input.B[i].first >> input.B[i].second;

        cout << solve(input) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        vector<int> A;
        int M;
        vector<pair<int, int>> B;

        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];

        cin >> M;
        B.resize(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        vector<int> C(N + 2, 0);
        for (int i = 0; i < M; ++i)
            C[B[i].second] = B[i].first;

        for (int i = N; i >= 1; --i)
            C[i] = max(C[i], C[i + 1]);

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            if (C[1] < A[i]) {
                failed = true;
                break;
            }

            int j = i;
            int mx = A[j];
            int en = 1;

            while (j + 1 < N) {
                if (C[en + 1] >= max(mx, A[j + 1])) {
                    en++;
                    j++;
                    mx = max(mx, A[j]);
                }
                else
                    break;
            }

            i = i + en - 1;
            res++;
        }
        if (failed)
            res = -1;
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

struct Input {
    int N;
    vector<int> A;
    int M;
    vector<pair<int, int>> B;
};

static int solve(Input& input) {
    auto& A = input.A;
    auto& B = input.B;
    auto N = input.N;
    auto M = input.M;

    sort(B.begin(), B.end());

    vector<int> mp(M, 0);
    reverse(B.begin(), B.end());
    for (int i = 0; i < M; ++i) {
        mp[i] = max(mp[i], B[i].second);
        if (i > 0)
            mp[i] = max(mp[i], mp[i - 1]);
    }

    reverse(B.begin(), B.end());
    reverse(mp.begin(), mp.end());

    bool failed = false;
    int res = 0;
    for (int i = 0; i < N; ++i) {
        auto it = upper_bound(
            B.begin(), B.end(), make_pair(A[i], -1),
            [](const pair<int, int>& lhs, const pair<int, int>& rhs) -> bool {
                return lhs.first < rhs.first;
            });
        if (it == B.end()) {
            failed = true;
            break;
        }
        auto idx = it - B.begin();
        bool was = false;
        for (int k = 1; k < mp[idx]; ++k) {
            if (i + k < N && it->first > A[i + k])
            {
                i++;
                was = true;
            }
        }
        if (was)
            i--;
        res++;
    }
    if (failed)
        return -1;
    return res;
}

static Input generate_random_input() {
    static const int N = 25;
    static const int K = 7;

    Input result;
    result.N = rand() % N + 1;
    for (int i = 0; i < result.N; ++i) {
        result.A.push_back(rand() % K + 1);
    }
    sort(result.A.begin(), result.A.end());
    result.M = rand() % N + 1;
    for (int i = 0; i < result.M; ++i) {
        result.B.push_back({ rand() % K + 1, rand() % N + 1 });
    }
    sort(result.B.begin(), result.B.end());
    return result;
}

static void print_input(const Input &input) {
    cout << input.N << "\n";
    for (int i = 0; i < input.N; ++i)
        cout << input.A[i] << " ";
    cout << "\n";
    cout << input.M << "\n";
    for (int i = 0; i < input.M; ++i)
        cout << input.B[i].first << " " << input.B[i].second << "\n";
}

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        Input input;

        cin >> input.N;
        input.A.resize(input.N);
        for (int i = 0; i < input.N; ++i)
            cin >> input.A[i];

        cin >> input.M;
        input.B.resize(input.M);
        for (int i = 0; i < input.M; ++i)
            cin >> input.B[i].first >> input.B[i].second;

        cout << solve(input) << "\n";
    }
}

static void test() {
    for (int i = 0; i < 10000; ++i) {
        auto input = generate_random_input();
        auto input1 = input;
        auto input2 = input;
        auto r1 = solve(input1);
        if (r1 > 5) {
            print_input(input);
            std::cout << "\n";
            std::cout << "Result: " << r1 << "\n";
            std::cout << "================================";
            std::cout << "\n";
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <assert.h>

using namespace std;

static void solve(std::int32_t test) {
    int T;
    cin >> T;
    for (int t = 0; t < T; ++t) {
        int N;
        vector<int> A;
        int M;
        vector<pair<int, int>> B;

        cin >> N;
        A.resize(N);
        for (int i = 0; i < N; ++i)
            cin >> A[i];

        cin >> M;
        B.resize(M);
        for (int i = 0; i < M; ++i)
            cin >> B[i].first >> B[i].second;

        vector<int> C(N + 2, 0);
        for (int i = 0; i < M; ++i)
            C[B[i].second] = B[i].first;

        for (int i = N; i >= 1; --i)
            C[i] = max(C[i], C[i + 1]);

        bool failed = false;
        int res = 0;
        for (int i = 0; i < N; ++i) {
            if (C[1] < A[i]) {
                failed = true;
                break;
            }

            int j = i;
            int mx = A[j];
            int en = 1;

            while (j < N) {
                mx = max(mx, A[j]);

                if (j + 1 < N && C[en + 1] >= max(mx, A[j + 1])) {
                    en++;
                    j++;
                }
                else
                    break;
            }

            i = i + en - 1;
            res++;
        }
        if (failed)
            res = -1;
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12) << fixed;
    solve(0);
    //test();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		if(max_power > heroes[m-1].first) {
			cout << -1 << endl; continue;
		}
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), (long long)0)) - heroes.begin();

			if(ind < m && heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1
1
5
4
1 1
2 1
3 1
4 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), 0)) - heroes.begin();

			if(ind < m && heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();
			if(heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), (long long)0)) - heroes.begin();

			if(ind < m && heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();
			if(ind >= m) {
				cout << 1; return;
			}
			if(heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();

			if(ind < m && heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();
			if(ind >= m) {
				cout << 1; return 0;
			}
			if(heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}

/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long t; cin >> t;
	while(t--) {
		long long n; cin >> n;
		vector<long long> monsters(n);
		for(long long i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		long long m; cin >> m;
		vector<pair<long long, long long>> heroes;
		for(long long i = 0; i < m; i++) {
			long long p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(long long i = m - 2; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		long long ans = 0;
		long long cur_monster = 1;
		long long max_power = monsters[0];
		for(long long i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			long long ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();
			//cout << ind << " ";
			if(heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}
/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <bits/stdc++.h>

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t; cin >> t;
	while(t--) {
		int n; cin >> n;
		vector<int> monsters(n);
		for(int i = 0; i < n; i++) {
			cin >> monsters[i];
		}
		int m; cin >> m;
		vector<pair<int, int>> heroes;
		for(int i = 0; i < m; i++) {
			int p, e; cin >> p >> e;
			heroes.push_back(make_pair(p, e));
		}
		sort(heroes.begin(), heroes.end());
		for(int i = m - 1; i >= 0; i--) {
			heroes[i].second = max(heroes[i+1].second, heroes[i].second);
		}
		int ans = 0;
		int cur_monster = 1;
		int max_power = monsters[0];
		for(int i = 1; i < n; i++) {
			if(max_power > heroes[m-1].first || monsters[i] > heroes[m-1].first) {
				ans = -1; break;
			}
			int ind = lower_bound(heroes.begin(), heroes.end(), make_pair(max(max_power, monsters[i]), cur_monster + 1)) - heroes.begin();
			//cout << ind << " ";
			if(heroes[ind].second < cur_monster + 1) {
				ans++;
				cur_monster = 1;
				max_power = monsters[i];
			}
			else {
				cur_monster++;
				max_power = max(max_power, monsters[i]);
			}
		}
		cout << (ans != -1 ? ans + 1 : - 1) << endl;
	}
}
/*
1 3 2 4
2 3 1 4
2 4 1 3
3 4 1 2
1 4 3 2
1 2 3 4

 */


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

const long long MOD = 1e9 + 7;

long long n, l, k;
long long a[1000001];
vector <long long> b;
vector <long long> c;
vector <vector <long long> > ans[2];

long long f[1000001], inv_f[1000001];
long long pr_sum[1000001];

long long pow(long long a, long long b) {
	if (b == 0)
		return 1;
	long long p = pow(a, b / 2);
	if (b % 2 == 0)
		return (p * p) % MOD;
	else
		return (((p * p) % MOD) * a) % MOD;
}

void init() {
	f[0] = 1;
	for (int i = 1; i < 1000001; i++)
		f[i] = (f[i - 1] * i) % MOD;
	for (int i = 0; i < 1000001; i++)
		inv_f[i] = pow(f[i], MOD - 2);
}

long long C(int n, int k) { return (((f[n] * inv_f[k]) % MOD) * inv_f[n - k]) % MOD; }

long long answer(int len, int last, bool type) {
	if (last < 0)
		return 0;
	if (ans[type][len][last] != -1)
		return ans[type][len][last];
	if ((len + 1) * n > l) {
		ans[type][len][last] = 0;
		return 0;
	}
	if (len == 0) {
		if (type) {
			ans[type][len][last] = 1;
			return 1;
		} else {
			ans[type][len][last] = last;
			return last;
		}
	}

	int left = 0, right = int(b.size());
	while (right - left > 1) {
		int mid= (left + right) / 2;
		if (b[mid] <= a[last])
			left = mid;
		else
			right = mid;
	}
	long long tmp = last - pr_sum[left] + 1;

	long long cnt = 0;
	if (type)
		cnt = (cnt + C(c[left], tmp) * (answer(len - 1, last, 1) + answer(len - 1, last, 0))) % MOD;
	else
		cnt = (cnt + answer(len, last - 1, 1) + answer(len, last - 1, 0)) % MOD;
	ans[type][len][last] = cnt;
	return cnt;
}

int y[1000001];
vector <int> t;
int a1[1000001];

int main() {
	ios_base::sync_with_stdio(false);
	init();

	cin >> n >> l >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		t.push_back(a[i]);
	}

	sort(t.begin(), t.end());

	for (int i = 0; i < n; i++) {
		int left = 0, right = int(t.size());
		while (right - left > 1) {
			int mid = (left + right) / 2;
			if (t[mid] <= a[i])
				left = mid;
			else
				right = mid;
		}
		a[i] = left;
	}

	for (int i = 0; i < 1000001; i++)
		y[i] = 0;
	for (int i = 0; i < l % n; i++)
		y[a[i]]++;

	for (int i = 999999; i >= 0; i--)
		y[i] += y[i + 1];
	for (int i = 0; i < n; i++)
		a1[i] = a[i];

	sort(a, a + n);
	b.push_back(a[0]);
	c.push_back(1);
	for (int i = 1; i < n; i++) {
		if (a[i] != b[int(b.size()) - 1]) {
			b.push_back(a[i]);
			c.push_back(1);
		} else
			c[int(c.size()) - 1]++;
	}

	pr_sum[0] = 0;
	for (int i = 1; i <= int(c.size()); i++)
		pr_sum[i] = pr_sum[i - 1] + c[i - 1];

	ans[0].resize(k);
	ans[1].resize(k);
	for (int i = 0; i < k; i++) {
		ans[0][i].resize(n);
		ans[1][i].resize(n);
	}

	for (int i = 0; i < k; i++)
		for (int j = 0; j < n; j++)
			ans[0][i][j] = ans[1][i][j] = -1;

	long long p = 0;
	for (int i = 0; i < k; i++)
		for (int j = 0; j < n; j++) {
			if (i + 1 < k)
				p = (p + ((y[a1[j]] * answer(i, j, 1)) % MOD) * C(l / n, i + 1)) % MOD;
			p = (p + answer(i, j, 1) * C(l / n, i + 1)) % MOD;
		}

	cout << (p + l % n) % MOD << endl;

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 1000000;
const ll MOD = 1000000007;
ll n, l, k, m, p, s;
pair <int, bool> a[MAXN];
pair <int, int> b[MAXN];
ll dp[MAXN];

int main() {
	cin >> n >> l >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = (i < l % n);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i > 0 && a[i - 1].first != a[i].first)
			++m;
		++b[m].first;
		b[m].second += a[i].second;
	}
	++m;
	p = l / n;
	// cout << m << ' ' << p << endl << endl;
	// for (int i = 0; i < m; ++i)
	// 	cout << b[i].first << ' ' << b[i].second << endl;
	// cout << endl;
	// cin >> n;
	// return 0;
	for (int i = 1; i <= k; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[j] = dp[j] * b[j].first % MOD;
			dp[j] = (j > 0) ? (dp[j] + dp[j - 1]) % MOD : dp[j];
			dp[j] = (i == 1) ? 1 : dp[j];
			s = (s + dp[j] * b[j].first % MOD * max(p - i + 1, 0ll) % MOD) % MOD;
			s = (s + dp[j] * b[j].second * (p + 1 >= i) % MOD) % MOD;
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 1000000;
const ll MOD = 1000000007;
ll n, l, k, m, p, s;
pair <int, bool> a[MAXN];
pair <int, int> b[MAXN];
ll dp[MAXN];

int main() {
	cin >> n >> l >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = (i < l % n);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i > 0 && a[i - 1].first != a[i].first)
			++m;
		++b[m].first;
		b[m].second += a[i].second;
	}
	++m;
	p = l / n % MOD;
	for (int i = 1; i <= k; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[j] = dp[j] * b[j].first % MOD;
			dp[j] = (j > 0) ? (dp[j] + dp[j - 1]) % MOD : dp[j];
			dp[j] = (i == 1) ? 1 : dp[j];
			s = (s + dp[j] * b[j].first % MOD * max(p - i + 1, 0ll) % MOD) % MOD;
			s = (s + dp[j] * b[j].second * (p + 1 >= i) % MOD) % MOD;
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAXN = 1000000;
const ll MOD = 1000000007;
ll n, l, k, m, p, s;
pair <int, bool> a[MAXN];
pair <int, int> b[MAXN];
ll dp[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> l >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = (i < l % n);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i > 0 && a[i - 1].first != a[i].first)
			++m;
		++b[m].first;
		b[m].second += a[i].second;
	}
	++m;
	p = l / n % MOD;
	for (int i = 1; i <= k; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[j] = dp[j] * b[j].first % MOD;
			dp[j] = (j > 0) ? (dp[j] + dp[j - 1]) % MOD : dp[j];
			dp[j] = (i == 1) ? 1 : dp[j];
			s = (s + dp[j] * b[j].first % MOD * max(p - i + 1, 0ll) % MOD) % MOD;
			s = (s + dp[j] * b[j].second * (p + 1 >= i) % MOD) % MOD;
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}


#include <fstream>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1000000;
const ll MOD = 1000000007;
ll n, l, k, m, p, s;
pair <int, bool> a[MAXN];
pair <int, int> b[MAXN];
ll dp[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> l >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = (i < l % n);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i > 0 && a[i - 1].first != a[i].first)
			++m;
		++b[m].first;
		b[m].second += a[i].second;
	}
	++m;
	p = l / n % MOD;
	for (int i = 1; i <= k; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[j] = dp[j] * b[j].first % MOD;
			dp[j] = (j > 0) ? (dp[j] + dp[j - 1]) % MOD : dp[j];
			dp[j] = (i == 1) ? 1 : dp[j];
			s = (s + dp[j] * b[j].first % MOD * max((p - i + 1 + MOD) % MOD, 0ll) % MOD) % MOD;
			s = (s + dp[j] * b[j].second * (p + 1 >= i) % MOD) % MOD;
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

const int MAXN = 1000000;
const ll MOD = 1000000007;
ll n, l, k, m, p, s;
pair <int, bool> a[MAXN];
pair <int, int> b[MAXN];
ll dp[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> l >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first;
		a[i].second = (i < l % n);
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		if (i > 0 && a[i - 1].first != a[i].first)
			++m;
		++b[m].first;
		b[m].second += a[i].second;
	}
	++m;
	p = l / n;
	for (int i = 1; i <= k; ++i) {
		for (int j = 0; j < m; ++j) {
			dp[j] = dp[j] * b[j].first % MOD;
			dp[j] = (j > 0) ? (dp[j] + dp[j - 1]) % MOD : dp[j];
			dp[j] = (i == 1) ? 1 : dp[j];
			s = (s + dp[j] * b[j].first % MOD * (max(p - i + 1, 0ll) % MOD) % MOD) % MOD;
			s = (s + dp[j] * b[j].second * (p + 1 >= i) % MOD) % MOD;
		}
	}
	cout << s << endl;
	cin >> n;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <map>
using namespace std;
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define REP(i, r, l) for(int i = r; i >= l; i--)
#define PB push_back
typedef long long ll;
double eps = 1e-6;
const int maxn = 1000100;
const int mod = 1e9 + 7;
const int INF = mod;
int a[maxn], b[maxn], hs[maxn], dp[maxn];
int main()
{
    int n, k;
    ll l;
    scanf("%d%lld%d", &n, &l, &k);
    FOR(i, 0, n-1) scanf("%d", &a[i]), b[i] = a[i];
    sort(a, a+n);
    int ans = 0;
    ll m = l / n, r = l % n;
    if(m <= 0) {
        cout<<l<<endl;
    }
    else {
        int pr = 0;
        for(int i = 0; i < n; i++)
        {
            while(pr < n - 1 && a[pr + 1] <= a[i]) pr++;
            hs[i] = pr;
        }

        for(int i = 0; i < n; i++) {
            dp[i] = 1;
            ans = (ans + m % mod * dp[i] % mod) % mod;
            if(i >= 1) dp[i] = dp[i-1] + 1;
        }
        if(r) ans = (ans + r) % mod;
        ll T = min((ll)k, m);
        for(int t = 1; t < T; t++)
        {
            for(int j = 0; j < n; j++)
            {
                int now = t * n + j, pre = (t - 1) * n + hs[j];
                dp[now] = dp[pre] % mod;
                ans = (ans + 1ll * (m - t) % mod * dp[now] % mod) % mod;
            }
            if(r)
            {
                for(int j = 0; j < r; j++)
                {
                    int id = upper_bound(a, a + n, b[j]) - a - 1;
                    ans = (ans + dp[t * n + id]) % mod;
                }
            }
            for(int j = 1; j < n; j++)
            {
                dp[t * n + j] = (dp[t * n + j] + dp[t * n + j - 1]) % mod;
            }
        }
        if(r)
        {
            for(int j = 0; j < r; j++)
            {
                int id = upper_bound(a, a + n, b[j]) - a - 1;
                ans = (ans + dp[(m-1) * n + id]) % mod;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <map>
using namespace std;
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define REP(i, r, l) for(int i = r; i >= l; i--)
#define PB push_back
typedef long long ll;
double eps = 1e-6;
const int maxn = 1000100;
const int mod = 1e9 + 7;

int a[maxn], b[maxn], hs[maxn], dp[maxn];
int main()
{
    int n, k;
    ll l;
    scanf("%d%lld%d", &n, &l, &k);
    FOR(i, 0, n-1) scanf("%d", &a[i]), b[i] = a[i];
    sort(a, a+n);
    int ans = 0;
    ll m = l / n, r = l % n;
    if(m <= 0) {
        cout<<l<<endl;
    }
    else {
        int pr = 0;
        for(int i = 0; i < n; i++)
        {
            while(pr < n - 1 && a[pr + 1] <= a[i]) pr++;
            hs[i] = pr;
        }

        for(int i = 0; i < n; i++) {
            dp[i] = 1;
            ans = (ans + m % mod * dp[i] % mod) % mod;
            if(i >= 1) dp[i] = dp[i-1] + 1;
        }
        if(r) ans = (ans + r) % mod;

        ll T = min((ll)k, m);
        for(int t = 1; t < T; t++)
        {
            for(int j = 0; j < n; j++)
            {
                int now = t * n + j, pre = (t - 1) * n + hs[j];
                dp[now] = dp[pre] % mod;
                ans = (ans + 1ll * (m - t) % mod * dp[now] % mod) % mod;
            }
            if(r)
            {
                for(int j = 0; j < r; j++)
                {
                    int id = upper_bound(a, a + n, b[j]) - a -1;
                    ans = (ans + dp[t * n + id]) % mod;
                }
            }
            for(int j = 1; j < n; j++)
            {
                dp[t * n + j] = (dp[t * n + j] + dp[t * n + j - 1]) % mod;
            }
        }
        if(r && k > m)
        {
            for(int j = 0; j < r; j++)
            {
                int id = upper_bound(a, a + n, b[j]) - a - 1;
                ans = (ans + dp[(T - 1) * n + id]) % mod;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <map>
using namespace std;
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define REP(i, r, l) for(int i = r; i >= l; i--)
#define PB push_back
typedef long long ll;
double eps = 1e-6;
const int maxn = 1000100;
const int mod = 1e9 + 7;

int a[maxn], b[maxn], hs[maxn], dp[maxn];
int main()
{
    int n, k;
    ll l;
    scanf("%d%lld%d", &n, &l, &k);
    FOR(i, 0, n-1) scanf("%d", &a[i]), b[i] = a[i];
    sort(a, a+n);
    int ans = 0;
    ll m = l / n, r = l % n;
    if(m <= 0) {
        cout<<l<<endl;
    }
    else {
        int pr = 0;
        for(int i = 0; i < n; i++)
        {
            while(pr < n - 1 && a[pr + 1] <= a[i]) pr++;
            hs[i] = pr;
        }

        for(int i = 0; i < n; i++) {
            dp[i] = 1;
            ans = (ans + m % mod * dp[i] % mod) % mod;
            if(i >= 1) dp[i] = dp[i-1] + 1;
        }
        if(r) ans = (ans + r) % mod;

        ll T = min((ll)k, m);
        for(int t = 1; t < T; t++)
        {
            for(int j = 0; j < n; j++)
            {
                int now = t * n + j, pre = (t - 1) * n + hs[j];
                dp[now] = dp[pre] % mod;
                ans = (ans + 1ll * (m - t) % mod * dp[now] % mod) % mod;
            }
            if(r)
            {
                for(int j = 0; j < r; j++)
                {
                    int id = upper_bound(a, a + n, b[j]) - a -1;
                    ans = (ans + dp[t * n + id]) % mod;
                }
            }
            for(int j = 1; j < n; j++)
            {
                dp[t * n + j] = (dp[t * n + j] + dp[t * n + j - 1]) % mod;
            }
        }
        if(r)
        {
            for(int j = 0; j < r; j++)
            {
                int id = upper_bound(a, a + n, b[j]) - a - 1;
                ans = (ans + dp[(T-1) * n + id]) % mod;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <map>
using namespace std;
#define FOR(i, l, r) for(int i = l; i <= r; i++)
#define REP(i, r, l) for(int i = r; i >= l; i--)
#define PB push_back
typedef long long ll;
double eps = 1e-6;
const int maxn = 1000100;
const int mod = 1e9 + 7;

int a[maxn], b[maxn], hs[maxn], dp[maxn];
int main()
{
    int n, k;
    ll l;
    scanf("%d%lld%d", &n, &l, &k);
    FOR(i, 0, n-1) scanf("%d", &a[i]), b[i] = a[i];
    sort(a, a+n);
    int ans = 0;
    ll m = l / n, r = l % n;
    if(m <= 0) {
        cout<<l<<endl;
    }
    else {
        int pr = 0;
        for(int i = 0; i < n; i++)
        {
            while(pr < n - 1 && a[pr + 1] <= a[i]) pr++;
            hs[i] = pr;
        }

        for(int i = 0; i < n; i++) {
            dp[i] = 1;
            ans = (ans + m % mod * dp[i] % mod) % mod;
            if(i >= 1) dp[i] = dp[i-1] + 1;
        }
        if(r) ans = (ans + r) % mod;

        ll T = min((ll)k, m);
        for(int t = 1; t < T; t++)
        {
            for(int j = 0; j < n; j++)
            {
                int now = t * n + j, pre = (t - 1) * n + hs[j];
                dp[now] = dp[pre] % mod;
                ans = (ans + 1ll * (m - t) % mod * dp[now] % mod) % mod;
            }
            if(r)
            {
                for(int j = 0; j < r; j++)
                {
                    int id = upper_bound(a, a + n, b[j]) - a -1;
                    ans = (ans + dp[t * n + id]) % mod;
                }
            }
            for(int j = 1; j < n; j++)
            {
                dp[t * n + j] = (dp[t * n + j] + dp[t * n + j - 1]) % mod;
            }
        }
        if(r)
        {
            for(int j = 0; j < r; j++)
            {
                int id = upper_bound(a, a + n, b[j]) - a - 1;
                ans = (ans + dp[T * n + id]) % mod;
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}


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

typedef long long LL;
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7;

map<int,int> val;

int a[maxn],r[maxn];
LL	C[maxn],R[maxn],dp[2][maxn];
vector<LL> d[maxn],sum[maxn];

int n,k;
LL l;

int main()
{
	//freopen("test.txt","r",stdin);

	scanf("%d %lld %d",&n,&l,&k);
	for(int i=0;i<n;++i) scanf("%d",a+i);
	if(n>=l)
	{
	   	printf("%lld\n",l);
		return 0;
	}
	LL B = l/n,ans = l%mod;
	int rem = l%n;

	for(int i=0;i<rem;++i) r[i] = a[i];

	sort(a,a+n);
	for(int i=0;i<n;++i) val[a[i]] = i;

	memset(dp,0,sizeof dp);
	int cur = 0;
	for(int i=0;i<n;++i) dp[1][i] = 1;

	for(int i=2;i<=min(B+1,(LL)k);++i)
	{
		LL sum = 0;
		int cnt = 0;
		for(int j=0;j<n;++j)
		{
			while( cnt<n && a[j] >= a[cnt]) sum = (sum + dp[cur^1][cnt])%mod,++cnt;
			dp[cur][j] = sum;
			d[i].push_back(sum);
		}
		cur^=1;
	}

	for(int i=2;i<=min(B+1,(LL)k);++i)
	{
		LL s = 0;
		for(int j=0;j<n;++j)
		{
	//		printf("%d %d %lld\n",i,j,d[i][j]);
			s = (s + d[i][j]) %mod;
			sum[i].push_back(s);
		}
	}

	for(int i=2;i<=min(B,(LL)k);++i) ans = (ans + (B-i+1)%mod*sum[i][n-1]%mod)%mod;
	for(int i=2;i<=min(B+1,(LL)k);++i)
		for(int j=0;j<rem;++j)
		{
			int p = val[r[j]];
			ans = (ans + d[i][p])%mod;
		}

	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7;

map<int,int> val;

int a[maxn],r[maxn];
LL	C[maxn],R[maxn];

int n,k;
LL l;

LL mul_mod(LL a,LL b,LL m) //防止long long溢出
{
	a%=m; b%=m;
	LL res = 0;
	while(b)
	{
		if(b&1) res = (res+a) % m;
		b >>= 1;
		a <<= 1;
		if(a>=m) a%=m;
	}
	return res;
}

LL pow_mod(LL a,LL n)
{
	LL res = 1;
	while(n)
	{
		if(n&1) res = (res*a) % mod;
		n>>=1;
		a = (a*a) %mod;
	}
	return res;
}

LL getC(LL n,LL m)
{
	if(n < m) return 0;
	if(m > n-m) m = n-m;
	LL s1 = 1,s2 = 1;
	for(LL i=0;i<m;++i)
	{
		s1 = (s1*(n-i)) %mod;
		s2 = (s2*(i+1)) %mod;
	}
	return s1*pow_mod(s2,mod-2)%mod;
}

int main()
{
	//freopen("test.txt","r",stdin);

	scanf("%d %lld %d",&n,&l,&k);
	for(int i=0;i<n;++i) scanf("%d",a+i);
	if(n>=l)
	{
	   	printf("%lld\n",l);
		return 0;
	}
	LL B = l/n,ans = l%mod;
	int rem = l%n;
	C[1] = B % mod;

	//printf("%lld %d\n",B,rem);
	for(int i=2;i<=min(B,(LL)k);++i)
	{
	   	C[i] = mul_mod(C[i-1],B-i+1,mod);
		C[i] = C[i]*pow_mod(i,mod-2)%mod;
	}

	for(int i=0;i<rem;++i) r[i] = a[i];

	val.clear();
	sort(a,a+n);
	for(int i=0;i<n;++i) val[a[i]] = i+1;

	for(int i = 1;i<=min(B,(LL)k)+1;++i)
	{
		if(i>=2 && i<=min(B,(LL)k)) ans = (ans+getC(i+n-1,n-1)*C[i]%mod)%mod;
		if(i==1) continue;

		for(int j = 0; j<rem;++j)
		{
			int p = val[r[j]];
	//		printf("***%d\n",p);
			ans = (ans+C[i-1]*getC(i-1+p-1,p-1))%mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long LL;
const int maxn = 1e6 + 10;
const LL mod = 1e9 + 7;

map<int,int> val;

int a[maxn],r[maxn];
LL	C[maxn],R[maxn];

int n,k;
LL l;

LL mul_mod(LL a,LL b,LL m) //防止long long溢出
{
	a%=m; b%=m;
	LL res = 0;
	while(b)
	{
		if(b&1) res = (res+a) % m;
		b >>= 1;
		a <<= 1;
		if(a>=m) a%=m;
	}
	return res;
}

LL pow_mod(LL a,LL n)
{
	LL res = 1;
	while(n)
	{
		if(n&1) res = (res*a) % mod;
		n>>=1;
		a = (a*a) %mod;
	}
	return res;
}

LL getC(LL n,LL m)
{
	if(n < m) return 0;
	if(m > n-m) m = n-m;
	LL s1 = 1,s2 = 1;
	for(LL i=0;i<m;++i)
	{
		s1 = (s1*(n-i)) %mod;
		s2 = (s2*(i+1)) %mod;
	}
	return s1*pow_mod(s2,mod-2)%mod;
}

int main()
{
//	freopen("test.txt","r",stdin);

	scanf("%d %lld %d",&n,&l,&k);
	for(int i=0;i<n;++i) scanf("%d",a+i);
	if(n>=l)
	{
	   	printf("%lld\n",l);
		return 0;
	}
	LL B = l/n,ans = l;
	int rem = l%n;
	C[1] = B % mod;

	//printf("%lld %d\n",B,rem);
	for(int i=2;i<=min(B,(LL)k);++i)
	{
	   	C[i] = mul_mod(C[i-1],B-i+1,mod);
		C[i] = C[i]*pow_mod(i,mod-2)%mod;
	}

	for(int i=0;i<rem;++i) r[i] = a[i];

	val.clear();
	sort(a,a+n);
	for(int i=0;i<n;++i) val[a[i]] = i+1;

	for(int i = 1;i<=min(B,(LL)k)+1;++i)
	{
		if(i>=2 && i<=min(B,(LL)k)) ans = (ans+getC(i+n-1,n-1)*C[i]%mod)%mod;
		if(i==1) continue;

		for(int j = 0; j<rem;++j)
		{
			int p = val[r[j]];
	//		printf("***%d\n",p);
			ans = (ans+C[i-1]*getC(i-1+p-1,p-1))%mod;
		}
	}

	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

const int N = 1e6+9;
const int MOD = 1e9+7;

int n, k;
long long l;
pair<int,int> a[N];
vector<long long> f[N];
long long s[N];
long long ans;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	cin >> n >> l >> k;
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i].first);
		a[i].second = i, f[i].push_back(0), f[i].push_back(1);
	}
	sort(a, a+n), s[1] = n;
	for(int j = 2; j <= k; ++j)
	{
		long long s = 0;
		for(int i = 0; i < n; ++i)
		{
			s = (s+f[a[i].second][j-1])%MOD;
			f[a[i].second].push_back(s);
			::s[j] = (::s[j]+s)%MOD;
		}
	}
	long long p = l/n, q = l%n;
	for(int i = 1; i <= k; ++i)
	{
		if(p+(q>0) < i) break;
		ans = (ans+(p-i+1)%MOD*s[i]%MOD)%MOD;
		for(int j = 0; j < q; ++j)
			ans = (ans+f[j][i])%MOD;
	}
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

const int N = 109;
const int K = 109;
const int L = 1009;
const int MOD = 1e9+7;

int n, l, k;
int a[N];
int f[L][K];
int ans;

inline void add(int &x, int y)
{
	x += y, x %= MOD;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("D.in", "r", stdin);
	freopen("bf.out", "w", stdout);
#endif

	cin >> n >> l >> k;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	for(int i = 1; i <= l; ++i)
		f[i][1] = 1;
	for(int i = n+1; i <= l; ++i)
	{
		int ti = (i-1)/n+1;
		for(int j = 2; j <= k; ++j)
			for(int p = (ti-2)*n+1; p <= (ti-1)*n; ++p)
				if(a[p-(ti-2)*n] <= a[i-(ti-1)*n])
					add(f[i][j], f[p][j-1]);
	}
	for(int i = 1; i <= l; ++i)
		for(int j = 1; j <= k; ++j)
			add(ans, f[i][j]);
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

const int N = 1e6+9;
const int MOD = 1e9+7;

int n, k;
long long l;
pair<int,int> a[N];
vector<long long> f[N];
long long s[N];
long long ans;

inline bool cmp(const pair<int,int> &a, const pair<int,int> &b)
{
	return a.first < b.first;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	cin >> n >> l >> k;
	for(int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i].first);
		a[i].second = i, f[i].push_back(0), f[i].push_back(1);
	}
	sort(a, a+n), s[1] = n;
	for(int j = 2; j <= k; ++j)
	{
		long long s = 0;
		for(int i = 0; i < n; ++i)
		{
			int p = i;s = (s+f[a[i].second][j-1])%MOD;
			while(p < n-1 && a[p+1].first == a[p].first)
				s = (s+f[a[++p].second][j-1])%MOD;
			for(int q = i; q <= p; ++q)
			{
				f[a[q].second].push_back(s);
				::s[j] = (::s[j]+s)%MOD;
			}
			i = p;
		}
	}
	long long p = l/n, q = l%n;
	for(int i = 1; i <= k; ++i)
	{
		if(p+(q>0) < i) break;
		ans = (ans+(p-i+1)%MOD*s[i]%MOD)%MOD;
		for(int j = 0; j < q; ++j)
			ans = (ans+f[j][i])%MOD;
	}
	cout << ans << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
bool cmp(unsigned long long o,unsigned long long p){
    return o>p;
}
map <unsigned long long,int> M;
unsigned long long n,l,k,p,kk,i,j,t,ans,tt,r,a[1100000],aa[1100000],f[1100000],b[1100000],bb[1100000],c[1100000];
int main(){
    unsigned long long mo=1000000007;
    scanf("%I64u %I64u %I64u",&n,&l,&k);
    for(i=1;i<=n;i++) scanf("%I64u",&a[i]);
    for(i=1;i<=n;i++) aa[i]=a[i];
    kk=l%n;
    if(l%n==0)  r=l/n; else r=l/n+1;
    sort(a+1,a+n+1,cmp);
    t=0;
    for(i=1;i<=n;i++){
        if(a[i]!=a[i-1]) {
            t++;
            M[a[i]]=t;
            c[t]=a[i];
            b[t]=n-i+1;
            //printf("%d ",b[t]);
        }
        f[t]++;
    }
    //printf("%d ",b[t]);
    /*if(kk!=0){
    sort(aa+1,aa+1+kk,cmp);tt=1;i=1;//cout<<kk<<endl;
    while(i<=kk){
        while((c[tt]<aa[i])&&(i<kk)) i++;
        bb[M[c[tt]]]=kk-i+1;
        //printf("%d ",bb[M[c[tt]]]);
        tt++;
        if(tt>t) break;
    }
    } else{
       for(i=1;i<=t;i++) bb[i]=b[i];
   }*/
   tt=0;
    sort(aa+1,aa+1+kk,cmp);
    for(i=1;i<=kk;i++){
        if(aa[i]!=aa[i-1]) {
            tt++;
            c[tt]=aa[i];
            //printf("%d ",b[M[c[tt]]]);
        }
        bb[tt]++;
    }
    ans=l%mo; //printf("%d\n",ans);
    for(i=2;i<=min(r,k);i++){
        if(kk!=0){
        for(j=1;j<=tt;j++){
            p=(b[j]*bb[M[c[j]]])%mo;
            ans=(ans+p)%mo;
        }
        for(j=1;j<=t;j++){
            b[j]=(f[j]*b[j])%mo;
            ans=(ans+((b[j]*((r-i)%mo))%mo))%mo;
        }
           for(j=t;j>0;j--){
                b[j]=b[j+1]+b[j];
            }
        } else {
            for(j=1;j<=t;j++){
            b[j]=(f[j]*b[j])%mo;
            ans=(ans+((b[j]*((r-i+1)%mo))%mo))%mo;
            }
            for(j=t;j>0;j--){
                b[j]=b[j+1]+b[j];
            }
        }//printf("%I64d ",ans);
    }
    printf("%I64u",(ans+mo)%mo);
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
bool cmp(unsigned long long o,unsigned long long p){
	return o>p;
}
map <unsigned long long,int> M;
unsigned long long n,l,k,p,kk,i,j,t,ans,tt,r,a[1100000],aa[1100000],f[1100000],b[1100000],bb[1100000],c[1100000];
int main(){
	unsigned long long mo=1000000007;
	scanf("%I64u %I64u %I64u",&n,&l,&k);
	for(i=1;i<=n;i++) scanf("%I64u",&a[i]);
	for(i=1;i<=n;i++) aa[i]=a[i];
	kk=l%n;
	if(l%n==0)  r=l/n; else r=l/n+1;
	sort(a+1,a+n+1,cmp);
	t=0;
	for(i=1;i<=n;i++){
		if(a[i]!=a[i-1]) {
			bb[t]=n-i+2;
		    t++;
		    M[a[i]]=t;
		    c[t]=a[i];
		    b[t]=n-i+1;
		    //printf("%d ",b[t]);
	    }
	    f[t]++;
    }
    bb[t]=1;//printf("%d ",b[t]);
    /*if(kk!=0){
    sort(aa+1,aa+1+kk,cmp);tt=1;i=1;//cout<<kk<<endl;
	while(i<=kk){
    	while((c[tt]<aa[i])&&(i<kk)) i++;
    	bb[M[c[tt]]]=kk-i+1;
        //printf("%d ",bb[M[c[tt]]]);
    	tt++;
    	if(tt>t) break;
	}
    } else{
       for(i=1;i<=t;i++) bb[i]=b[i];
   }*/
   tt=0;
   	for(i=1;i<=kk;i++){
		if(aa[i]!=aa[i-1]) {
		    tt++;
		    c[tt]=aa[i];
		    //printf("%d ",b[M[c[tt]]]);
	    }
    }
    ans=l%mo; //printf("%d\n",ans);
    for(i=2;i<=min(r,k);i++){
    	if(kk!=0){
    	for(j=1;j<=tt;j++){
    		p=(f[j]*bb[M[c[j]]])%mo;
    		ans=(ans+p)%mo;
		}
    	for(j=1;j<=t;j++){
    		f[j]=(f[j]*b[j])%mo;
    		ans=(ans+((f[j]*(r-i))%mo))%mo;
		}
	    } else {
	    	for(j=1;j<=t;j++){
    		f[j]=(f[j]*b[j])%mo;
    		ans=(ans+((f[j]*(r-i+1))%mo))%mo;
		}
		}//printf("%I64d ",ans);
	}
	printf("%I64u",(ans+mo)%mo);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define w(i) T[(i)].w
#define ls(i) T[(i)].ls
#define rs(i) T[(i)].rs
using namespace std;
typedef __int64 LL;
const int N=2e6+10;
const int mod=1e9+7;
int sta[N],top;
int aa[N];
int Find(int x)
{
    int l=0,r=top;
    while(l<r-1)
    {
        int mid=(l+r)/2;
        if(sta[mid]==x)return mid;
        if(sta[mid]>x)r=mid;
        else l=mid;
    }
}
LL dp[N],sum[N];
int num[N];
int n,k;
LL l;
int main()
{
#ifdef GLQ
freopen("data.txt","r",stdin);
#endif // GLQ
    while(scanf("%d%I64d%d",&n,&l,&k)!=EOF)
    {
        top=1;sta[0]=-1;for(int i=0;i<n;i++){scanf("%d",&aa[i]);sta[top++]=aa[i];}
        sort(sta,sta+top);top=unique(sta,sta+top)-sta;
//        for(int i=0;i<top;i++)
//        {
//            printf("%d ",sta[i]);
//        }printf("\n");
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)
        {
            aa[i]=Find(aa[i]);num[aa[i]]++;
        }
//        for(int i=0;i<n;i++)
//        {
//            printf("%d ",aa[i]);
//        }printf("\n");
//        for(int i=1;i<top;i++)
//        {
//            printf("%d ",num[i]);
//        }printf("\n");
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
//        for(int i=1;i<top;i++)
//        {
//            printf("%d ",num[i]);
//        }printf("\n");
        for(int i=1;i<top;i++)sum[i]=1;
        for(int i=1;i<=k;i++)
        {
            sum[i*top+0]=0;
            for(int j=1;j<top;j++)
            {
//                dp[i][j]=(num[j]-num[j+1])*sum[i-1][j];
//                sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
                dp[i*top+j]=(num[j]-num[j+1])*sum[(i-1)*top+j]%mod;
                sum[i*top+j]=(sum[i*top+j-1]+dp[i*top+j])%mod;
            }
        }
        //printf("%I64d %I64d\n",sum[1*top+top-1],sum[2*top+top-1]);
        LL t=l/n;
        //printf("%I64d\n",t);
        LL ans=0;
        for(int i=1;i<=k;i++)
        {
            if(i>t)break;
            ans+=((t-i+1)%mod)*sum[i*top+top-1]%mod;ans%=mod;
        }
        //printf("%I64d\n",ans);
        t=l%n;
        memset(num,0,sizeof(num));
        //printf("%I64d\n",t);
        for(int i=0;i<t;i++)num[aa[i]]++;
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)
        {
            if(num[i]-num[i+1]==0)continue;
            LL ed=min((LL)k-1,l/n);
            //printf("%d:",i);
            for(int j=0;j<=ed;j++)
            {
                ans+=(num[i]-num[i+1])*sum[j*top+i]%mod;ans%=mod;
                //printf("%d--%I64d  ",j,ans);
            }
            //printf("\n");
        }
        printf("%I64d\n",ans%mod);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define w(i) T[(i)].w
#define ls(i) T[(i)].ls
#define rs(i) T[(i)].rs
using namespace std;
typedef __int64 LL;
const int N=2e6+10;
const int mod=1e9+7;
int sta[N],top;
int aa[N];
int Find(int x)
{
    int l=0,r=top;
    while(l<r-1)
    {
        int mid=(l+r)/2;
        if(sta[mid]==x)return mid;
        if(sta[mid]>x)r=mid;
        else l=mid;
    }
}
LL dp[N],sum[N];
int num[N];
int n,k;
LL l;
int main()
{
#ifdef GLQ
freopen("data.txt","r",stdin);
#endif // GLQ
    while(scanf("%d%I64d%d",&n,&l,&k)!=EOF)
    {
        top=1;sta[0]=-1;for(int i=0;i<n;i++){scanf("%d",&aa[i]);sta[top++]=aa[i];}
        sort(sta,sta+top);top=unique(sta,sta+top)-sta;
//        for(int i=0;i<top;i++)
//        {
//            printf("%d ",sta[i]);
//        }printf("\n");
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)
        {
            aa[i]=Find(aa[i]);num[aa[i]]++;
        }
//        for(int i=0;i<n;i++)
//        {
//            printf("%d ",aa[i]);
//        }printf("\n");
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)sum[i]=1;
        for(int i=1;i<=k;i++)
        {
            sum[i*top+0]=0;
            for(int j=1;j<top;j++)
            {
//                dp[i][j]=(num[j]-num[j+1])*sum[i-1][j];
//                sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
                dp[i*top+j]=(num[j]-num[j+1])*sum[(i-1)*top+j]%mod;
                sum[i*top+j]=(sum[i*top+j-1]+dp[i*top+j])%mod;
            }
        }
        LL t=l/n;
        LL ans=0;
        for(int i=1;i<=k;i++)
        {
            if(i>t)break;
            ans+=(t-i+1)*sum[i*top+top-1]%mod;ans%=mod;
        }
        //printf("%I64d\n",ans);
        t=l%n;
        memset(num,0,sizeof(num));
        for(int i=0;i<t;i++)num[aa[i]]++;
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)
        {
            if(num[i]-num[i+1]==0)continue;
            LL ed=min((LL)k-1,(LL)l/n);
            //printf("%d:",i);
            for(int j=0;j<=ed;j++)
            {
                ans+=(num[i]-num[i+1])*sum[j*top+i]%mod;ans%=mod;
                //printf("%d--%I64d  ",j,ans);
            }
            //printf("\n");
        }
        printf("%I64d\n",ans%mod);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define w(i) T[(i)].w
#define ls(i) T[(i)].ls
#define rs(i) T[(i)].rs
using namespace std;
typedef __int64 LL;
const int N=2e6+10;
const int mod=1e9+7;
int sta[N],top;
int aa[N];
int Find(int x)
{
    int l=0,r=top;
    while(l<r-1)
    {
        int mid=(l+r)/2;
        if(sta[mid]==x)return mid;
        if(sta[mid]>x)r=mid;
        else l=mid;
    }
}
LL dp[N],sum[N];
int num[N];
int n,k;
LL l;
int main()
{
#ifdef GLQ
freopen("data.txt","r",stdin);
#endif // GLQ
    while(scanf("%d%I64d%d",&n,&l,&k)!=EOF)
    {
        top=1;sta[0]=-1;for(int i=0;i<n;i++){scanf("%d",&aa[i]);sta[top++]=aa[i];}
        sort(sta,sta+top);top=unique(sta,sta+top)-sta;
//        for(int i=0;i<top;i++)
//        {
//            printf("%d ",sta[i]);
//        }printf("\n");
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)
        {
            aa[i]=Find(aa[i]);num[aa[i]]++;
        }
//        for(int i=0;i<n;i++)
//        {
//            printf("%d ",aa[i]);
//        }printf("\n");
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)sum[i]=1;
        for(int i=1;i<=k;i++)
        {
            sum[i*top+0]=0;
            for(int j=1;j<top;j++)
            {
//                dp[i][j]=(num[j]-num[j+1])*sum[i-1][j];
//                sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
                dp[i*top+j]=(num[j]-num[j+1])*sum[(i-1)*top+j]%mod;
                sum[i*top+j]=(sum[i*top+j-1]+dp[i*top+j])%mod;
            }
        }
        LL t=l/n;
        LL ans=0;
        for(int i=1;i<=k;i++)
        {
            if(i>t)break;
            ans+=(t-i+1)*sum[i*top+top-1]%mod;ans%=mod;
        }
        printf("%I64d\n",ans);
        t=l%n;
        memset(num,0,sizeof(num));
        for(int i=0;i<t;i++)num[aa[i]]++;
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)
        {
            if(num[i]-num[i+1]==0)continue;
            LL ed=min((LL)k-1,(LL)l/n);
            //printf("%d:",i);
            for(int j=0;j<=ed;j++)
            {
                ans+=(num[i]-num[i+1])*sum[j*top+i]%mod;ans%=mod;
                //printf("%d--%I64d  ",j,ans);
            }
            //printf("\n");
        }
        printf("%I64d\n",ans%mod);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define w(i) T[(i)].w
#define ls(i) T[(i)].ls
#define rs(i) T[(i)].rs
using namespace std;
typedef __int64 LL;
const int N=2e6+10;
const int mod=1e9+7;
int sta[N],top;
int aa[N];
int Find(int x)
{
    int l=0,r=top;
    while(l<r-1)
    {
        int mid=(l+r)/2;
        if(sta[mid]==x)return mid;
        if(sta[mid]>x)r=mid;
        else l=mid;
    }
}
LL dp[N],sum[N];
int num[N];
int n,l,k;
int main()
{
#ifdef GLQ
freopen("data.txt","r",stdin);
#endif // GLQ
    while(scanf("%d%d%d",&n,&l,&k)!=EOF)
    {
        top=1;sta[0]=-1;for(int i=0;i<n;i++){scanf("%d",&aa[i]);sta[top++]=aa[i];}
        sort(sta,sta+top);top=unique(sta,sta+top)-sta;
//        for(int i=0;i<top;i++)
//        {
//            printf("%d ",sta[i]);
//        }printf("\n");
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++)
        {
            aa[i]=Find(aa[i]);num[aa[i]]++;
        }
//        for(int i=0;i<n;i++)
//        {
//            printf("%d ",aa[i]);
//        }printf("\n");
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)sum[i]=1;
        for(int i=1;i<=k;i++)
        {
            sum[i*top+0]=0;
            for(int j=1;j<top;j++)
            {
//                dp[i][j]=(num[j]-num[j+1])*sum[i-1][j];
//                sum[i][j]=(sum[i][j-1]+dp[i][j])%mod;
                dp[i*top+j]=(num[j]-num[j+1])*sum[(i-1)*top+j]%mod;
                sum[i*top+j]=(sum[i*top+j-1]+dp[i*top+j])%mod;
            }
        }
        int t=l/n;
        LL ans=0;
        for(int i=1;i<=k;i++)
        {
            if(i>t)break;
            ans+=(t-i+1)*sum[i*top+top-1]%mod;ans%=mod;
        }
        //printf("%I64d\n",ans);
        t=l%n;
        memset(num,0,sizeof(num));
        for(int i=0;i<t;i++)num[aa[i]]++;
        for(int i=top-1;i>=0;i--)num[i]+=num[i+1];
        for(int i=1;i<top;i++)
        {
            if(num[i]-num[i+1]==0)continue;
            int ed=min(k-1,l/n);
            //printf("%d:",i);
            for(int j=0;j<=ed;j++)
            {
                ans+=(num[i]-num[i+1])*sum[j*top+i]%mod;ans%=mod;
                //printf("%d--%I64d  ",j,ans);
            }
            //printf("\n");
        }
        printf("%I64d\n",ans%mod);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;

int n, k;
long long l;
int a[MAXN];
vector <pair<int, int> > p;
long long f[MAXN], ff[MAXN];
// cur_val, val_on_line

long long ans;

int main()
{
    cin >> n >> l >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n*k; ++i) p.push_back(make_pair(a[i%n], i));

    sort(p.begin(), p.end());

    for (int i = 0; i < n*k; ++i){
        int cur_p = p[i].second;

        if (cur_p < n)
            f[cur_p] = 1;
        else
            f[cur_p] = ff[cur_p/n-1];

        ff[cur_p/n] = (ff[cur_p/n] + f[cur_p]) % MOD;

        if (cur_p < l){
            long long x = (l - 1 - cur_p + n)/n;
            ans = (ans + (x%MOD) * f[cur_p]) % MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;

int n, l, k;
int a[MAXN];
vector <pair<int, int> > p;
long long f[MAXN], ff[MAXN];
// cur_val, val_on_line

long long ans;

int main()
{
    cin >> n >> l >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n*k; ++i) p.push_back(make_pair(a[i%n], i));

    sort(p.begin(), p.end());

    for (int i = 0; i < n*k; ++i){
        int cur_p = p[i].second;

        if (cur_p < n)
            f[cur_p] = 1;
        else
            f[cur_p] = ff[cur_p/n-1];

        ff[cur_p/n] = (ff[cur_p/n] + f[cur_p]) % MOD;

        if (cur_p < l){
            long long x = (l - 1 - cur_p + n)/n;
            ans = (ans + (x%MOD) * f[cur_p]) % MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;

int n, k;
long long l;
int a[MAXN];
vector <pair<int, int> > p;
long long f[MAXN], ff[MAXN];
// cur_val, val_on_line

long long ans;

int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> l >> k;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n*k; ++i) p.push_back(make_pair(a[i%n], i));

    sort(p.begin(), p.end());

    for (int i = 0; i < n*k; ++i){
        int cur_p = p[i].second;

        if (cur_p < n)
            f[cur_p] = 1;
        else
            f[cur_p] = ff[cur_p/n-1];

        ff[cur_p/n] = (ff[cur_p/n] + f[cur_p]) % MOD;

        if (cur_p < l){
            long long x = (l - 1 - cur_p + n)/n;
            ans = (ans + ((x%MOD) * f[cur_p])%MOD) % MOD;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, k;
long long l;
vector<int> a, A, idx_max;
vector<vector<long long> > dp, acc;
map<int, int> idx;
long long mod = 1000000007;
void build()
{
	dp.resize(k + 1);
	acc.resize(k + 1);
	for(int i = 0; i<=k; i++)
	{
		dp[i].resize(n);
		acc[i].resize(n);
	}
	for(int i = 0; i<n; i++)
	{
		dp[1][i] = 1ll;
		acc[1][i] = (long long)i + 1ll;
	}
	for(int i = 2; i<=k; i++)
	{
		dp[i][0] = acc[i - 1][idx_max[0]];
		acc[i][0] = dp[i][0];
		for(int j = 1; j<n; j++)
		{
			dp[i][j] = acc[i - 1][idx_max[j]];
			acc[i][j] = acc[i][j - 1] + dp[i][j];
			acc[i][j] %= mod;
		}
	}
}

long long solve()
{
	long long nc = l/(long long)n;
	if(nc == 0ll) return l%mod;
	//printf("nc = %lld\n", nc);
	long long solution = 0ll;
	for(long long i = nc*n; i<l; i++)
	{
		for(int j = 2; j<=(int)min((long long)k, nc + 1ll); j++)
		{
			solution += dp[j][idx[a[(int)(i%(long long)n)]]];
			solution %= mod;
		}
	}
	for(long long i = 2ll; i<=min(nc, (long long)k); i++)
	{
		solution += ((nc - i + 1ll)%mod)*acc[(int)i][n - 1];
		solution %= mod;
	}
	return (solution + l)%mod;
}

int main()
{
	scanf("%d %lld %d", &n, &l, &k);
	a.resize(n);
	idx_max.resize(n);
	for(int i = 0; i<n; i++) scanf("%d", &a[i]);
	A = a;
	sort(A.begin(), A.end());
	idx_max[n - 1] = n - 1;
	for(int i = 0; i<n; i++) idx[A[i]] = i;
	for(int i = n - 2; i >= 0; i--)
	{
		if(A[i] != A[i + 1]) idx_max[i] = i;
		else idx_max[i] = idx_max[i + 1];
	}
	/*printf("BEGIN\n");
	for(int i = 0; i<n; i++) printf("%d ", A[i]);
	printf("\n");
	for(int i = 0; i<n; i++) printf("%d ", idx_max[i]);*/

	build();
	printf("%lld\n", solve());
}


#include <bits/stdc++.h>
using namespace std;
int n, k;
long long l;
vector<int> a, A, idx_max;
vector<vector<long long> > dp, acc;
map<int, int> idx;
long long mod = 1000000007;
void build()
{
	dp.resize(k + 1);
	acc.resize(k + 1);
	for(int i = 0; i<=k; i++)
	{
		dp[i].resize(n);
		acc[i].resize(n);
	}
	for(int i = 0; i<n; i++)
	{
		dp[1][i] = 1ll;
		acc[1][i] = (long long)i + 1ll;
	}
	for(int i = 2; i<=k; i++)
	{
		dp[i][0] = acc[i - 1][idx_max[0]];
		acc[i][0] = dp[i][0];
		for(int j = 1; j<n; j++)
		{
			dp[i][j] = acc[i - 1][idx_max[j]];
			acc[i][j] = acc[i][j - 1] + dp[i][j];
			acc[i][j] %= mod;
		}
	}
}

long long solve()
{
	long long nc = l/(long long)n;
	long long solution = 0ll;
	for(long long i = nc*n; i<l; i++)
	{
		for(int j = 2; j<=(int)min((long long)k, nc + 1); j++)
		{
			solution += dp[j][idx[a[(int)(i%(long long)n)]]];
			solution %= mod;
		}
	}
	for(long long i = 2ll; i<=nc; i++)
	{
		solution += (nc - i + 1ll)*acc[(int)i][n - 1];
		solution %= mod;
	}
	return (solution + l)%mod;
}

int main()
{
	scanf("%d %lld %d", &n, &l, &k);
	a.resize(n);
	idx_max.resize(n);
	for(int i = 0; i<n; i++) scanf("%d", &a[i]);
	A = a;
	sort(A.begin(), A.end());
	idx_max[n - 1] = n - 1;
	for(int i = 0; i<n; i++) idx[A[i]] = i;
	for(int i = n - 2; i >= 0; i--)
	{
		if(A[i] != A[i + 1]) idx_max[i] = i;
		else idx_max[i] = idx_max[i + 1];
	}
	build();

	printf("%lld\n", solve());
}


#include <bits/stdc++.h>
using namespace std;
int n, k;
long long l;
vector<int> a, A, idx_max;
vector<vector<long long> > dp, acc;
map<int, int> idx;
long long mod = 1000000007;
void build()
{
	dp.resize(k + 1);
	acc.resize(k + 1);
	for(int i = 0; i<=k; i++)
	{
		dp[i].resize(n);
		acc[i].resize(n);
	}
	for(int i = 0; i<n; i++)
	{
		dp[1][i] = 1ll;
		acc[1][i] = (long long)i + 1ll;
	}
	for(int i = 2; i<=k; i++)
	{
		dp[i][0] = acc[i - 1][idx_max[0]];
		acc[i][0] = dp[i][0];
		for(int j = 1; j<n; j++)
		{
			dp[i][j] = acc[i - 1][idx_max[j]];
			acc[i][j] = acc[i][j - 1] + dp[i][j];
			acc[i][j] %= mod;
		}
	}
}

long long solve()
{
	long long nc = l/(long long)n;
	if(nc == 0ll) return l%mod;
	long long solution = 0ll;
	for(long long i = nc*n; i<l; i++)
	{
		for(int j = 2; j<=(int)min((long long)k, nc + 1); j++)
		{
			solution += dp[j][idx[a[(int)(i%(long long)n)]]];
			solution %= mod;
		}
	}
	for(long long i = 2ll; i<=(int)min(nc, (long long)k); i++)
	{
		solution += (nc - i + 1ll)*acc[(int)i][n - 1];
		solution %= mod;
	}
	return (solution + l)%mod;
}

int main()
{
	scanf("%d %lld %d", &n, &l, &k);
	a.resize(n);
	idx_max.resize(n);
	for(int i = 0; i<n; i++) scanf("%d", &a[i]);
	A = a;
	sort(A.begin(), A.end());
	idx_max[n - 1] = n - 1;
	for(int i = 0; i<n; i++) idx[A[i]] = i;
	for(int i = n - 2; i >= 0; i--)
	{
		if(A[i] != A[i + 1]) idx_max[i] = i;
		else idx_max[i] = idx_max[i + 1];
	}
	build();
	printf("%lld\n", solve());
}