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

Solution 1 (runtime: 828 ms):
#include<bits/stdc++.h>
using namespace std;

int main(){
int tt; cin>>tt;
while(tt--){
    int n,m; cin>>n>>m;
    multiset<int> m1,m2;
    int sum1 = 0,sum2 = 0;
    for(int i=0;i<n;i++){int ele; cin>>ele; m1.insert(ele); sum1+=ele;}
    for(int i=0;i<m;i++){int ele; cin>>ele; m2.insert(ele); sum2+=ele;}

    if(sum1 != sum2){cout<<"No"<<endl; continue;}

    while(m2.size()>0){
        int ele = *m2.begin();
        m2.erase(m2.begin());
        // auto it = m1.find(ele);
        // cout<<
        if(m1.find(ele) != m1.end()){
            m1.erase(m1.find(ele));
        }
        else if(ele < *m1.begin()){
            m2.insert(ele);
            break;
        }
        else{
            m2.insert(ele/2);
            m2.insert(ele/2 + (ele%2!=0));
        }
    }
    if(m1.size()>0 or m2.size()>0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}
}

Solution 2 (runtime: 296 ms):
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

template <typename T>
using ordered_set =
    __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag,
    __gnu_pbds::tree_order_statistics_node_update>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
using vvpi = vector<vector<pair<int, int>>>;
using vvpl = vector<vector<pair<long long, long long>>>;
using vb = vector<bool>;
using vs = vector<string>;
using si = set<int>;
using mpii = map<int, int>;

#define fori(i, a, b) for (int i = a; i < b; ++i)
#define fore(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i > b; --i)
#define forre(i, a, b) for (int i = a; i >= b; --i)

#define pb push_back
#define sc static_cast
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) (int32_t)x.size()
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define approx(a) fixed << setprecision(a)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define INFF LONG_LONG_MIN
#define inf INT_MAX
#define inff INT_MIN
#define nl '\n'

template <class T> void read(vector<T> &v);
template <class F, class S> void read(pair<F, S> &p);
template <class T, size_t Z> void read(array<T, Z> &a);
template <class T> void read(T &x) {
	cin >> x;
}
template <class R, class... T> void read(R &r, T &...t) {
	read(r);
	read(t...);
};
template <class T> void read(vector<T> &v) {
	for (auto &x : v)
		read(x);
}
template <class F, class S> void read(pair<F, S> &p) {
	read(p.ff, p.ss);
}
template <class T, size_t Z> void read(array<T, Z> &a) {
	for (auto &x : a)
		read(x);
}

template <class F, class S> void pr(const pair<F, S> &x);
template <class T> void pr(const T &x) {
	cout << x;
}
template <class R, class... T> void pr(const R &r, const T &...t) {
	pr(r);
	pr(t...);
}
template <class F, class S> void pr(const pair<F, S> &x) {
	pr("{", x.ff, ", ", x.ss, "}");
}
void ps() {
	pr("\n");
}
template <class T> void ps(const T &x) {
	pr(x);
	ps();
}
template <class T> void ps(vector<T> &v) {
	for (auto &x : v)
		pr(x, ' ');
	ps();
}
template <class T, size_t Z> void ps(const array<T, Z> &a) {
	for (auto &x : a)
		pr(x, ' ');
	ps();
}
template <class F, class S> void ps(const pair<F, S> &x) {
	pr(x.ff, ' ', x.ss);
	ps();
}
template <class R, class... T> void ps(const R &r, const T &...t) {
	pr(r, ' ');
	ps(t...);
}

#define definp()                                                               \
  int n;                                                                       \
  read(n);                                                                     \
  vl a(n);                                                                     \
  read(a);
#define int long long

void exec_once() {
}
bool tc = 1;
#define MOD (long long)(1e9 + 7)
bool fx(mpii &mp, int x){
    if(x == 1){
        if(mp[1]-->0) return 1; 
        return 0;
    }
    if(mp[x] > 0){
        mp[x]--;
        return 1;
    }
    return fx(mp, x/2) && fx(mp, (x+1)/2);
}
void solve(int tn [[maybe_unused]]) {
	int n, m;
	read(n,m);
	vl b(m);
	mpii mp;
	int s2 = 0;
	fori(i,0,n) {
		int x;
		read(x);
		mp[x]++;
		s2+=x;
	}
	read(b);
	sort(all(b));
	int s1 = accumulate(all(b), 0LL);
    if(s1!=s2)return ps("NO");	
	fori(i,0,m) 
	    if(!fx(mp, b[i]))
	        return ps("NO");


	ps("YES");

}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	exec_once();
	int t = 1;
	if (tc)
		cin >> t;
	fore(tn, 1, t) solve(tn);
	return 0;
}