https://codeforces.com/problemset/problem/2061/D

#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define lowbit(x) x&(-x)
#define endl '\n'
using ll = long long;
using pii = pair<int,int>;
const double PI = acos(-1);
const int N=2e5+10;
void solve(){
	int n,m;cin>>n>>m;
	priority_queue<ll> qa,qb;
	for(int i=1;i<=n;i++){
		ll x;cin>>x;
		qa.push(x);
	}
		
	for(int i=1;i<=m;i++){
		ll x;cin>>x;
		qb.push(x);
	}
	while(!qa.empty()&&!qb.empty()){
		if(qb.size()>qa.size()){
			cout<<"NO"<<endl;
			return;
		}
		ll a=qa.top();
		ll b=qb.top();
		if(a==b) {
			qa.pop();
			qb.pop();
		}
		else if(a>b){
			cout<<"NO"<<endl;
			return;
		}
		else{
			qb.pop();
			qb.push(b/2);
			qb.push((b+1)/2);
		}
	}
	if(!qa.empty()||!qb.empty()){
		cout<<"NO"<<endl;
	}
	else cout<<"YES"<<endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	
	int T = 1;
	cin>>T;
	while (T--) {
		solve();
	}
	
	return 0;
}



可以将b数组拆成跟a数组一样