Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 343 ms):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dep(i, a, b) for (int i = a; i >= b; i--)
#define lowbit(x) x & -x
#define mems(a, x) memset((a), (x), sizeof(a))
#define pb emplace_back
 
typedef pair<int, int> pii;
const int N = 2e5 + 10;
int mod = 998244353;

void solve()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1), b(m + 1);
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, m) cin >> b[i];

    priority_queue<int>q;
    rep(i, 1, m)q.push(b[i]);
    map<int,int>mp;
    rep(i, 1, n)mp[a[i]] ++ ;

    int sum = 0;
    while(q.size())
    {
        int x = q.top();
        if(mp[x] == 0)
        {
            sum++;
            if(sum > n)
            {
                cout << "No" << endl;
                return ;
            }
            q.push(x / 2);
            if(x % 2) q.push((x / 2 + 1));
            else q.push(x / 2);
        }
        else
        {
            mp[x] -- ;
        }
        q.pop();
    }

    rep(i, 1, n)
    {
        if(mp[a[i]])
        {
            cout << "No" << endl;
            return ;
        }
    }
    cout << "Yes" << endl;
    return ;
}
 
signed main()
{
    cin.tie(0), ios_base::sync_with_stdio(false);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
 
/*
1 1 1 1
4 3 3 2 2 2 1 1 1 1
5
1 10 2 3 3
5 3 1
9
9 223 361 347 302 335 839
0 0 1 2
 */

Solution 2 (runtime: 687 ms):
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define ENDL '\n'
#define MAXN 100001
#define mod 998244353
#define ft first
#define sc second
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef long double ld;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;

ll n, m, k;

ll binpow(ll a, ll b){
	if(b==0)return 1;
	if(b==1)return a;
	ll num=binpow(a,b>>1)%mod, p=1;
	if(b%2)p=a;
	ll part=(num*num)%mod;
	return (part*p)%mod;
}

const int mov_f[]={-1,0,1, 0};
const int mov_c[]={0,-1,0, 1};

void solve(){
  cin>>n;
  /*vll v(n);

  ll a=0, b=0;
  map<ll, ll>mp;
  for(int i=0; i<n; i++){
     cin>>v[i];
     mp[v[i]]++;
  }

  vll fact(n+1);
  fact[0]=1;
  for(int i=1; i<=n; i++)fact[i]=(fact[i-1]*i)%mod;

  ll dp[n][2];
  for(int i=0; i<n; i++)dp[i][0]=dp[i][1]=0;
  dp[0][0]=1;
  ll c=0;

  set<ll>s1, s0;
  if(v[0]!=0){
    dp[0][1]=-1; c++;
    s0.insert(0);
    s1.insert(1);
    }
  dp[0][1]++;


  for(int i=1; i<n; i++){
    dp[i][0]=dp[i-1][1];


    //cout<<i<<" "<<dp[i][0]<<" "<<dp[i][1]<<ENDL;
  }

  cout<<(dp[n-1][0]+dp[n-1][1])%mod<<ENDL;*/

  cin>>m;
  vll a(n), b(m);
  map<ll, ll>ca, cb;
  for(int i=0; i<n; i++){
    cin>>a[i];
    ca[a[i]]++;
  }

  for(int i=0; i<m; i++){
    cin>>b[i];
    cb[b[i]]++;
  }

  multiset<ll>sa, sb;
  for(int i:a)sa.insert(i);
  for(int i: b)sb.insert(i);

  while(sb.size() && sb.size()<sa.size()){
    ll x=*sb.rbegin();
    sb.erase(--sb.end());

    if(sa.find(x)!=sa.end()){
        sa.erase(sa.find(x));
        continue;
    }

    sb.insert(x/2);
    sb.insert((x+1)/2);
  }

  for(ll i: sb){
    if(sa.find(i)==sa.end()){
        cout<<"NO"<<ENDL;
        return;
    }
    sa.erase(sa.find(i));
  }

  for(ll i: sa){
    if(sb.find(i)==sb.end()){
        cout<<"NO"<<ENDL;
        return;
    }
    
    sb.erase(sb.find(i));
  }

  cout<<"YES"<<ENDL;


}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cout.precision(0);
    cout<<fixed;
	//freopen("fencedin.in", "r", stdin);
	//freopen("fencedin.out", "w", stdout);

	int t=1;
    cin>>t;
	while(t--)solve();

	return 0;
}