#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef tree< long long ,null_type,less< long long > ,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree< long long ,null_type,less_equal< long long > ,rb_tree_tag,tree_order_statistics_node_update> multi_indexed_set;
const int N= 1e6 + 2 ;
const int M= 1e9 + 7 ;
long long NN= 316 ,MM,S,K;
long long test_case;
#define ll long long
#define lp(i,a,b) for(ll i=a;i<=b;i++)
#define rlp(i,a,b) for(ll i=a;i>=b;i--)
#define vec vector<long long>
#define pb push_back
#define rpb pop_back
#define f first
#define s second
#define el "\n"
#define pri(ara,n) for(ll i=1;i<=n;i++)cout<<ara[i]<<" ";cout<<el;
#define priv(vec) for(auto va:vec)cout<<va<<" ";cout<<"\n";
#define srt(ara,n) sort(ara+1,ara+1+n);
#define srtv(vec) sort(vec.begin(), vec.end());
#define revv(vec) reverse(vec.begin(), vec.end());
#define coutl cout<<"Case "<<test_case<<": "
#define in(ara,n) cin>>n;lp(i,1,n)cin>>ara[i];
#define all(ara,n,m) lp(i,1,n)ara[i]=m;
#define index(indexed_Set,val) indexed_Set.order_of_key(val)
#define value(indexed_Set,ind) *indexed_Set.find_by_order(ind)
#define pi 2*acos(0.0)
#define Mems(dp,n) memset(dp,n,sizeof(dp))
bool myComparison( const pair< pair< ll,ll> ,ll> & a,const pair< pair< ll,ll> ,ll> & b) // for vector sorting 1st element small to learge (if same then second element large to small)
{
if ( a.f .f == b.f .f ) return a.f .s > b.f .s ;
else return a.f .f < b.f .f ;
}
bool cmp1( const pair< ll,ll> & a,const pair< ll,ll> & b) // for vector sorting 1st element small to learge (if same then second element large to small)
{
// return a>b;
if ( a.f == b.f ) return a.s < b.s ;
else return a.f > b.f ;
}
ll lcm( ll a,ll b)
{
return ( a* b) / ( __gcd( a,b) ) ;
}
ll gcd( ll a,ll b)
{
return __gcd( a,b) ;
}
//ll arr[1001][1001];
ll ara[ N] ,ara1[ N] ,indx[ N] ,vis[ N] ;
vector< ll> v[ N] ;
ll input[ N] ,store_sum_data_for_seg_tree[ N] ;
// vector<ll>v[N];
//vector<ll>v(N),inv(N);
//ll arr[1001][1001];
ll built_sum_seg_tree( ll a,ll b,ll n)
{
if ( a== b) return store_sum_data_for_seg_tree[ n] = input[ a] ;
ll mid= ( a+ b) / 2 ;
return store_sum_data_for_seg_tree[ n] = ( built_sum_seg_tree( a,mid,2 * n) + built_sum_seg_tree( mid+ 1 ,b,2 * n+ 1 ) ) ;
}
ll find_sum_from_seg_tree( ll x,ll y,ll a,ll b,ll n) // first two variable is my range for finding sum
{
if ( b< x|| a> y) return 0 ;
if ( a>= x&& b<= y) return store_sum_data_for_seg_tree[ n] ;
ll mid= ( a+ b) / 2 ;
return ( find_sum_from_seg_tree( x,y,a,mid,2 * n) + find_sum_from_seg_tree( x,y,mid+ 1 ,b,2 * n+ 1 ) ) ;
}
ll change_value_in_seg_tree( ll in,ll va,ll a,ll b,ll n)
{
if ( in< a|| in> b) return store_sum_data_for_seg_tree[ n] ;
if ( a== b) return store_sum_data_for_seg_tree[ n] = ( input[ a] - va) ;
ll mid= ( a+ b) / 2 ;
return store_sum_data_for_seg_tree[ n] = ( change_value_in_seg_tree( in,va,a,mid,2 * n) + change_value_in_seg_tree( in,va,mid+ 1 ,b,2 * n+ 1 ) ) ;
}
void solve( )
{
ll i,j,k,l,m,n,o,p,q,r,t,a,b,h,c,d,e,f,x,y,z,ans,ans1;
cin >> n>> m>> k;
lp( i,0 ,4 * n) input[ i] = store_sum_data_for_seg_tree[ i] = 0 ;
built_sum_seg_tree( 1 ,n,1 ) ;
lp( i,1 ,n) vis[ i] = 0 ;
lp( i,1 ,n)
{
cin >> ara[ i] ;
indx[ ara[ i] ] = i;
}
lp( i,1 ,m)
{
cin >> ara1[ i] ;
vis[ ara1[ i] ] = 1 ;
}
ll flag= 0 ;
lp( i,1 ,m- 1 )
{
if ( indx[ ara1[ i] ] > indx[ ara1[ i+ 1 ] ] ) flag= 1 ;
}
if ( flag)
{
cout << "NO" << el;
return ;
}
set< ll> st;
st.insert ( 0 ) ;
st.insert ( n+ 1 ) ;
multiset< ll> mul_st;
lp( i,1 ,k)
{
cin >> a;
mul_st.insert ( a) ;
}
rlp( i,n,1 )
{
if ( vis[ i] )
{
st.insert ( indx[ i] ) ;
}
else
{
a= indx[ i] ;
auto va= st.upper_bound ( a) ;
ll up= ( * va) ;
ll dn= ( * ( -- va) ) ;
ll len= up- dn- 1 ;
ll tem1= find_sum_from_seg_tree( dn+ 1 ,up- 1 ,1 ,n,1 ) ;
len- = tem1;
auto va1= mul_st.upper_bound ( len) ;
if ( va1== mul_st.begin ( ) )
{
cout << "NO" << el;
return ;
}
va1-- ;
mul_st.erase ( va1) ;
// st.insert(indx[i]);
change_value_in_seg_tree( indx[ i] ,- 1 ,1 ,n,1 ) ;
}
}
cout << "YES" << el;
}
int main( )
{
fast;
ll t= 1 ;
cin >> t;
test_case= 1 ;
while ( t-- )
{
solve( ) ;
test_case++ ;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZmFzdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKIAp0eXBlZGVmIHRyZWU8bG9uZyBsb25nLG51bGxfdHlwZSxsZXNzPGxvbmcgbG9uZz4scmJfdHJlZV90YWcsdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlPiBpbmRleGVkX3NldDsKdHlwZWRlZiB0cmVlPGxvbmcgbG9uZyxudWxsX3R5cGUsbGVzc19lcXVhbDxsb25nIGxvbmc+LHJiX3RyZWVfdGFnLHRyZW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mE7CiAgICAgICAgbXVsX3N0Lmluc2VydChhKTsKICAgIH0KCiAgICBybHAoaSxuLDEpCiAgICB7CiAgICAgICAgaWYodmlzW2ldKQogICAgICAgIHsKICAgICAgICAgICAgc3QuaW5zZXJ0KGluZHhbaV0pOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBhPWluZHhbaV07CiAgICAgICAgICAgIGF1dG8gdmE9c3QudXBwZXJfYm91bmQoYSk7CiAgICAgICAgICAgIGxsIHVwPSgqdmEpOwogICAgICAgICAgICBsbCBkbj0oKigtLXZhKSk7CgogICAgICAgICAgICBsbCBsZW49dXAtZG4tMTsKCiAgICAgICAgICAgIGxsIHRlbTE9ZmluZF9zdW1fZnJvbV9zZWdfdHJlZShkbisxLHVwLTEsMSxuLDEpOwogICAgICAgICAgICBsZW4tPXRlbTE7CgogICAgICAgICAgICBhdXRvIHZhMT1tdWxfc3QudXBwZXJfYm91bmQobGVuKTsKCiAgICAgICAgICAgIGlmKHZhMT09bXVsX3N0LmJlZ2luKCkpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGNvdXQ8PCJOTyI8PGVsOwogICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9IAogICAgICAgICAgICB2YTEtLTsKCiAgICAgICAgICAgIG11bF9zdC5lcmFzZSh2YTEpOwoKICAgICAgICAgICAgLy8gc3QuaW5zZXJ0KGluZHhbaV0pOwoKICAgICAgICAgICAgY2hhbmdlX3ZhbHVlX2luX3NlZ190cmVlKGluZHhbaV0sLTEsMSxuLDEpOwoKICAgICAgICB9CiAgICB9CgogICAgY291dDw8IllFUyI8PGVsOwp9CgppbnQgbWFpbigpCnsKICAgIGZhc3Q7CiAgICBsbCB0PTE7CiAgICBjaW4+PnQ7CiAgICB0ZXN0X2Nhc2U9MTsKICAgIHdoaWxlKHQtLSkKICAgIHsKICAgICAgICBzb2x2ZSgpOwogICAgICAgIHRlc3RfY2FzZSsrOwogICAgfQp9IA==