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

Solution 1 (runtime: 436 ms):
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || हर हर महादेव!
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lld;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
#define yep               \
   cout << "Yes" << endl; \
   return;
#define nope             \
   cout << "No" << endl; \
   return;
#define pb push_back
#define int long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define sq(a) a *a
#define nl endl;
#define inf (1LL << 60)
const int Mod = 1e9 + 7;
#define all(x) x.begin(), x.end()

int inv(ll i)
{
   if (i == 1)
     return 1;
   return (Mod - ((Mod / i) * inv(Mod % i)) % Mod) % Mod;
}
int mod(int a, int m)
{
   return (a % m + m) % m;
}
int mod_mul(int a, int b, int m = Mod) { return mod(mod(a, m) * mod(b, m), m); }
int mod_pow(int a, int b, int m)
{
   if (b == 0)
      return 1;
   else
      return mod_mul(a, mod_pow(a, b - 1, m), m);
}
int mod_div(int a, int b, int d = Mod)
{
   return mod_mul(a, mod_pow(b, d - 2, d));
}
ll power(ll a, ll b, int M = Mod)
{
   a = a % M;
   int result = 1;
   while (b > 0)
   {
      if (b & 1)
         result = (result * 1LL * a) % M;
      a = (a * 1LL * a) % M;
      b >>= 1;
   }
   return result;
}
// uint64_t ; for 64 bits
// uint32_t ; for 32 bits
// no of subarrays if atleast k elements are required from an array of size n = (n+1-k)*(n+2-k)/2;
//__builtin_popcount(x) = returns set bits
void solve()
{
   ll n;
   cin >> n;
   int m;
   cin >> m;
   multiset<int> a, b;
   for (int i = 0; i < n; i++){
      int x;
      cin >> x;
      a.insert(x);
   }
   for (int i = 0; i < m; i++){
      int x;
      cin >> x;
      b.insert(x);
   }
   vector<int> rem;
   for(auto i : a){
      if(b.find(i) != b.end()){
         rem.push_back(i);
         b.erase(b.find(i));
      }
   }
   for(auto i : rem){
      a.erase(a.find(i));
   }
   while(b.size() && a.size()){

      int ind = *(b.begin());
      b.erase(b.begin());
      // cout << ind << endl;
      int one = (ind + 1) / 2;
      int two = ind / 2;
      if(one == 0 || two == 0){
         nope;
      }
      if(a.find(two) != a.end()){
         a.erase(a.find(two));
      }else{
         b.insert(two);
      }
      if(a.find(one) != a.end()){
         a.erase(a.find(one));
      }else{
         b.insert(one);
      }
   }
   if(a.size() == 0 && b.size() == 0){
      yep;
   }else{
      nope;
   }

}
signed main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--)
   {
      solve();
   }
}
/*
|| ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् उर्वारुकमिव बन्धनान्मृ त्योर्मुक्षीय मामृतात् || जय शिव शम्भू !
*/

Solution 2 (runtime: 359 ms):
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace meta{
    void print_case(int case_no){
        std::cout << "Case #" << case_no << ": ";
    }
}
namespace datastruct {
    // A doubly-linked list that only supports modify and (pseudo) deletion at pointer
    class DeleteOnly_DLL {
    public:
        std::vector<int> values;
        std::vector<int> prev;
        std::vector<int> next;
        int pointer;
        
        DeleteOnly_DLL(int size) {
            values.resize(size);
            prev.resize(size);
            next.resize(size);
            
            for (int i = 0; i < size; i++) {
                prev[i] = (i + size - 1) % size;
                next[i] = (i +        1) % size;
            }
            
            pointer = 0;
        }
        
        int current() {
            return values[pointer];
        }
        
        // Set value at pointer and move pointer to next
        void set_and_move(int val) {
            values[pointer] = val;
            pointer = next[pointer];
        }
        
        // "Delete" node and move pointer to next
        void erase() {
            if (prev[pointer] != -1) {
                next[prev[pointer]] = next[pointer];
            }
            if (next[pointer] != -1) {
                prev[next[pointer]] = prev[pointer];
            }
            
            int next_id = next[pointer];
            prev[pointer] = next[pointer] = -1;
            pointer = next_id;
        }
    };
}
namespace algos{
template <typename T, typename = void>
struct is_iterable : std::false_type {};

// to check if type is iterable
// this gets used only when we can call std::begin() and std::end() on that type
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T&>())),
                                  decltype(std::end(std::declval<T&>()))
                                 >
                  > : std::true_type {};

// Here is a helper:
template <typename T>
constexpr bool is_iterable_v = is_iterable<T>::value;

template<typename T>
std::vector<std::pair<T, int>> rle(std::vector<T> &a)
{
	// find run length encoding as a pair<>
	std::vector<std::pair<T,int>> encoding;
	T prev_value = a[0];
	int count = 1;
	for(int i=1;i < a.size(); ++i){
		if(a[i] == prev_value)count++;
		else{
			encoding.emplace_back(prev_value, count);
			prev_value = a[i];
			count = 1;
		}
	}
	encoding.emplace_back(prev_value, count);
	return encoding;
}

template<typename T>
void rm_dupl(std::vector<T> &a)
{
	// removes consecutive duplicates from vector<>
	// unique will move them to the front of the array
	auto iter = std::unique(a.begin(), a.end());
	a.erase(iter, a.end());
	return;
}

template<typename T>
std::vector<std::pair<T, int>> get_count(std::vector<T> a, bool sorted=false)
{
    if(!sorted) sort(a.begin(), a.end());
    std::vector<std::pair<T, int>> cnt;
    T curr = a[0];
    int count = 0;
    for(int i=0;i < a.size(); ++i){
        if(a[i] != curr){
            cnt.emplace_back(curr, count);
            count = 0;
            curr = a[i];
        }
        count++;
    }
    cnt.emplace_back(curr, count);
    return cnt;
}

long long int bin_exp(long long int base, long long int exp, long long int mod){
	if(exp==0)return 1;
	long long int half_exp = bin_exp(base, exp>>1, mod);
	if(exp&1){
		return (((half_exp*half_exp)%mod)*base)%mod;
	}
	return (half_exp*half_exp)%mod;
}

long long int mod_inv(long long a, long long mod){
	return bin_exp(a, mod-2, mod);
}

template<class T>
void print(T &iterable){
	if constexpr(std::is_arithmetic_v<T>|| std::is_same<T, std::string>::value){
		std::cout << iterable << ' ';
	}else if constexpr(std::is_convertible_v<T, std::pair<int,int>>){
		std::cout << iterable.first << ',' << iterable.second << ' ';
	}else if constexpr(is_iterable_v<T>){
		for(auto k : iterable)print(k);
		std::cout << std::endl;
	}
}
long long nxor(long long n){
    // returns the xor of all positive
    // integers from 1...n(including)
    if(n < 0)return 0;
    switch(n%4){
        case 0:
            return n;
        case 1:
            return 1;
        case 2:
            return n+1;
        case 3:
            return 0;
    }
    return 0;
}

long long range_xor(long long l, long long r){
    // returns to xor of the range [l,r]
    // both including
    return nxor(r) ^ nxor(l - 1);
}
}

#define ll long long
#define ld long double
#define pi pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define vf vector<float>
#define vd vector<double>
#define vs vector<string>
const long long int MOD = 1e9 + 7;
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main()
{
    ios_base::sync_with_stdio(false);
    // for interactive questions remove the tie!
    cin.tie(NULL);
    // a: 1 1 2 3
    // b: 1 2 5  
    // with each operation I have to 
    // there should be a "way" to make x
    // -> there should be a "way" to make x/2
    int t;cin>>t;
    while(t-->0){
        int n,m;cin>>n>>m;
        map<int,int>a;
        vi b(m);
        for(int i=0;i <n;++i){int tmp;cin>>tmp;a[tmp]++;}
        for(auto &e:b)cin>>e;
        int possible=1;
        function<void(int,int,int,int)> found = [&](int v1,int c1, int v2, int c2){
            // v2 >= v1
            // cout << v1 << ' ' <<c1 << ' ' << v2 <<' ' << c2<< endl;
            if(c1==0&&c2==0)return;
            if(c1!=0&&v1==0){possible=0;return;}
            auto itr1=a.find(v1);
            auto itr2=a.find(v2);
            if(itr1!=a.end()){
                if(itr1->second>c1){itr1->second-=c1;c1=0;}
                else{c1-=itr1->second;itr1->second=0;}
            }
            if(itr2!=a.end()){
                if(itr2->second>c2){itr2->second-=c2;c2=0;}
                else{c2-=itr2->second;itr2->second=0;}
            }
            // algos::print(a);
            // cout << c1 << ' ' << c2 << endl;
            int nc1=0,nc2=0;
            if(v1%2){
                nc1=c1,nc2=c1+2*c2;
            }else{
                nc1=2*c1+c2,nc2=c2;
            }
            if(v2==1&&nc2!=0){possible=0;return;}
            found(v1/2,nc1,(v2+1)/2,nc2);
        };
        for(auto itr=b.begin();itr!=b.end();++itr){
            int val=*itr;
            found(val,1,val,0);
        }
        for(auto e: a){if(e.second!=0)possible=0;}
        if(possible){cout << "Yes";}
        else cout << "No";
        cout << endl;
    }
    return 0;
}