//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

vector < int > adj[N], ans;
int a[N], b[N];

void bfs(int u)
{
    queue < int > q;
    q.push(u);
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        ans.push_back(v);
        b[v] ++;
        for (auto u : adj[v])
        {
            b[u] ++;
            if (a[u] == b[u])
                q.push(u);
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, u, v;
    cin >> n >> m;
    for (int i = 0; i < m; i ++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    for (int i = 1; i <= n; i ++)
        if (a[i] == b[i])
            bfs(i);
    cout << ans.size() << '\n';
    for (auto x : ans)
        cout << x << ' ';
    return 0;
}


#include <bits/stdc++.h>

#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int MAX = 1e5 + 5;
vector<int> adj[MAX];
int a[MAX], b[MAX];
int n, m;

int main() {
    cin>>n>>m;
	fori(i, 0, m) {
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	fori(i, 1, n + 1) {
	    cin>>a[i];
	}

	queue<int> q;
	fori(i, 1, n + 1) {
		if(a[i] == b[i]) {
			q.push(i);
		}
	}

	vector<int> ans;
	while(!q.empty()) {
		int cur = q.front(); q.pop();
		ans.push_back(cur);
		b[cur]++;
		for(auto &each : adj[cur]) {
			b[each]++;
			if(b[each] == a[each]) {
				q.push(each);
			}
		}
	}

	cout<<(int) ans.size()<<endl;
	for(auto &each : ans) {
	    cout<<each<<' ';
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,x,y;
	scanf("%d %d", &n, &m);
	vector<vector<int>>adj(n);
	for(int i=0;i<m;i++){
		scanf("%d %d",&x, &y);
		x--, y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	queue<int>q;
	vector<int>a(n),cnt(n);
	for(int i=0;i<n;i++){
		scanf("%d", &a[i]);
		if(a[i]==0) q.push(i);
	}
	set<int>ret;
	while(!q.empty()){
		int cur=q.front(); q.pop();
		ret.insert(cur);
		cnt[cur]++;
		for(const int& nxt:adj[cur]){
			cnt[nxt]++;
			if(cnt[nxt]==a[nxt]){
				q.push(nxt);
			}
		}
	}
	printf("%d\n",ret.size());
	for(const int& r:ret){
		printf("%d ", r+1);
	}
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
long long const inf = 1e18;
int const mxn = 2e5+10;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

int l[mxn],megh[mxn];
queue <int > q;
vector <int > adj[mxn],ans;
int main(){
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for (int i = 1;i<=n;i++){
		int a;
		cin>>a;
		l[i]=a;
		if(a==0)
			q.push(i);
	}
	while (q.size()){
		int v = q.front();
		megh[v]++;
		q.pop();
		ans.push_back(v);
		for (auto i : adj[v]){
			megh[i]++;
			if (megh[i]==l[i])
				q.push(i);
		}
	}
	cout<<ans.size()<<endl;
	for (auto i : ans)
		cout<<i<<" ";
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const ll maxn= 1e6+12;
ll n, m, a[maxn], x, y;
vector<int> ad[maxn], kh;
queue<int>q;
bool vison[maxn];

ll main(){
    IOS;
    cin >> n >> m;
    lp(i, m){
        cin >> x >> y;
        x--;
        y--;
        ad[x].pb(y);
        ad[y].pb(x);
    }
    lp(i, n){
		cin >> a[i];
		q.push(i);
    }
    while(!q.empty()){
        x=q.front();
        q.pop();
		kh.pb(x);
 		a[x]--;
        for(ll w: ad[x]){
			a[w]--;
            if(a[w]>0)
	            q.push(w);
        }
    }
	cout << kh.size() << '\n';
	lp(i, kh.size())
		cout << kh[i]+1 << ' ';

}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

ll n, m, k;
const ll maxn= 1e6+12;
vector<int> ad[maxn];
queue<int>q;
ll d[maxn], a[maxn], x, y, dif;
bool vison[maxn], cnt;
string str;

ll main(){
    IOS;
    cin >> n >> m;
    lp(i, m){
        cin >> x >> y;
        x--;
        y--;
        ad[x].pb(y);
        ad[y].pb(x);
    }
    lp(i, n){
		cin >> a[i];
        if (d[i]< a[i])
            q.push(i);
    }
    while(!q.empty()){
        x=q.front();
        q.pop();
 		dif= (a[x]-d[x]) +1;
		lp(i, dif){
			str+= to_string(x+1) + ' ';
			cnt++;
		}
        for(ll w: ad[x]){
        	d[w]+=dif;
            if(d[w]<a[w])
	            q.push(w);
        }
    }
	cout << cnt << '\n' << str;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

ll n, m, k;
const ll maxn= 1e6+12;
vector<int> ad[maxn];
queue<int>q;
ll d[maxn], a[maxn], x, y, dif, cnt;
bool vison[maxn];
string str;

ll main(){
    IOS;
    cin >> n >> m;
    lp(i, m){
        cin >> x >> y;
        x--;
        y--;
        ad[x].pb(y);
        ad[y].pb(x);
    }
    lp(i, n){
		cin >> a[i];
        if (d[i]< a[i])
            q.push(i);
    }
    while(!q.empty()){
        x=q.front();
        q.pop();
 		dif= (a[x]-d[x]) +1;
		lp(i, dif){
			str+= to_string(x+1) + ' ';
			cnt++;
		}
        for(ll w: ad[x]){
        	d[w]+=dif;
            if(d[w]<a[w])
	            q.push(w);
        }
    }
	cout << cnt << '\n' << str;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

typedef long long int lli;
typedef int ll;
#define lp(i, wwww) for(int i=0; i<wwww; i++)
#define lp2(i, a, b) for (int i=a; i<b; i++)
#define pb push_back
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)

const ll maxn= 1e6+12;
ll n, m, a[maxn], x, y;
vector<int> ad[maxn], kh;
queue<int>q;

ll main(){
    IOS;
    cin >> n >> m;
    lp(i, m){
        cin >> x >> y;
        x--;
        y--;
        ad[x].pb(y);
        ad[y].pb(x);
    }
    lp(i, n){
		cin >> a[i];
		if(!a[i])
			q.push(i);
    }
    while(!q.empty()){
        x=q.front();
        q.pop();
		kh.pb(x);
 		a[x]--;
        for(ll w: ad[x]){
			a[w]--;
            if(!a[w])
	            q.push(w);
        }
    }
	cout << kh.size() << '\n';
	lp(i, kh.size())
		cout << kh[i]+1 << ' ';

}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
vector <int> adl[maxn],an;
int a[maxn],b[maxn];
int main()
{
	int n,m;
	cin >> n >> m;
	queue <int> q;
	for(int i = 0;i<m;i++)
	{
		int v1,v2;
		cin >> v1 >> v2;
		v1--;
		v2--;
		adl[v1].push_back(v2);
		adl[v2].push_back(v1);
	}
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
		if(a[i]==b[i])
		{
			q.push(i);
			an.push_back(i);
		}
	}
	while(q.size())
	{
		int p = q.front();
		q.pop();
		for(int v:adl[p])
		{
			b[v] ++;
            if(a[v]==b[v]){
				q.push(v);
				an.push_back(v);
            }
		}
	}
	cout << an.size() << "\n";
	for(int  i = 0;i<an.size();i++)
		cout << an[i]+1 <<" ";
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
vector <int> adl[maxn],an;
int a[maxn],b[maxn];
int main()
{
	int n,m;
	cin >> n >> m;
	queue <int> q;
	for(int i = 0;i<m;i++)
	{
		int v1,v2;
		cin >> v1 >> v2;
		adl[v1].push_back(v2);
		adl[v2].push_back(v1);
	}
	for(int i = 0;i<n;i++)
	{
		int t;
		cin >> t;
		a[i] = t;
		if(a[i]==b[i])
		{
			q.push(i);
		}
	}
	while(q.size())
	{
		int p = q.front();
		q.pop();
		an.push_back(p);
		for(int v:adl[p])
		{
			b[v] ++;
		       	if(a[v]==b[v])
				q.push(v);
		}
	}
	cout << an.size() << "\n";
	for(int  i = 0;i<an.size();i++)
		cout << an[i] <<" ";
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
vector <int> adl[maxn],an;
int a[maxn],b[maxn];
int main()
{
	int n,m;
	cin >> n >> m;
	queue <int> q;
	for(int i = 0;i<m;i++)
	{
		int v1,v2;
		cin >> v1 >> v2;
		adl[v1].push_back(v2);
		adl[v2].push_back(v1);
	}
	for(int i = 0;i<n;i++)
	{
		int t;
		cin >> t;
		a[i] = t;
		if(a[i]==b[i])
		{
			q.push(i);
		}
	}
	while(q.size())
	{
		int p = q.front();
		q.pop();
		an.push_back(p);
		for(int v:adl[p])
		{
			b[v] ++;
		       	if(a[v]==b[v])
				q.push(v);
		}
	}
	cout << an.size() << "\n";
	for(int  i = 0;i<p.size();i++)
		cout << an[i] <<" ";
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stack>
#include <deque>
#include <iterator>
#include <tuple>
#include <iomanip>
#define pb push_back
#define mp make_pair
#define int long long
#define fi first
#define se second
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int power(int x,int y, int p)
{
    int res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

signed main()
{
    fast
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        vector<int> v[n+1],ans;
        for(int i=0;i<m;i++)
        {
            int x,y;
            cin>>x>>y;
            v[x].pb(y);
            v[y].pb(x);
        }
        bool vis[n+1];
        memset(vis,0,sizeof(vis));
        queue<int> q;
        int a[n+1];
        int check[n+1];
        memset(check,0,sizeof(check));
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]==check[i])
            {
                q.push(i);
            }
        }
        while(!q.empty())
        {
            int f=q.front();
            q.pop();
            if(check[f]!=a[f])
                continue;
            ans.pb(f);
            vis[f]=1;
            check[f]++;
            for(int i=0;i<v[f].size();i++)
            {
                check[v[f][i]]++;
                if(check[v[f][i]]==a[v[f][i]]&&vis[v[f][i]]==false)
                {
                    q.push(v[f][i]);

                }
            }
        }
        cout<<ans.size()<<endl;
        for(int i=0;i<ans.size();i++)
            cout<<ans[i]<<" ";
        cout<<endl;

    }
}


#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
using namespace std;
vector <int> v[100010];
queue <int> q;
bool javab[100010];
int a[100010];
int b[100010];
main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0 ; i<m ; i++)
  {
      int u , k;

      cin>>u>>k;
      u--;
      k--;
      v[u].pb(k);
      v[k].pb(u);
  }

  for(int i=0 ; i<n ; i++)
  {
      cin>>a[i];
  }

  for(int i=0 ; i<n ; i++)
  {
      if(b[i]==a[i])
      {
          q.push(i);

      }
  }
  while(q.empty()==0)
  {
      int x=q.front();
       q.pop();
      javab[x]=1;
      for(int i:v[x])
      {
          b[i]+=1;
          if(b[i]==a[i])
          {
              q.push(i);

          }
      }
  }
  int x=0;
    for(int i=0 ; i<n ; i++)
  {
        if(javab[i]==1)
         x+=1;

}
cout<<x<<endl;
  for(int i=0 ; i<n ; i++)
  {
        if(javab[i]==1)
            cout<<i+1<<" ";
}
}


#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
using namespace std;
vector <int> v[10000];
queue <int> q;
bool javab[100000];
int a[100000];
int b[100000];
main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0 ; i<m ; i++)
  {
      int u , k;

      cin>>u>>k;
      u--;
      k--;
      v[u].pb(k);
      v[k].pb(u);
  }

  for(int i=0 ; i<n ; i++)
  {
      cin>>a[i];
  }

  for(int i=0 ; i<n ; i++)
  {
      if(b[i]==a[i])
      {
          q.push(i);

      }
  }
  while(q.empty()==0)
  {
      int x=q.front();
       q.pop();
      javab[x]=1;
      for(int i:v[x])
      {
          b[i]+=1;
          if(b[i]==a[i])
          {
              q.push(i);

          }
      }
  }
  int x=0;
    for(int i=0 ; i<n ; i++)
  {
        if(javab[i]==1)
         x+=1;

}
cout<<x<<endl;
  for(int i=0 ; i<n ; i++)
  {
        if(javab[i]==1)
            cout<<i+1<<" ";
}
}


#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
using namespace std;
vector <int> v[10000];
queue <int> q;
bool javab[100000];
int a[100000];
int b[100000];
main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0 ; i<m ; i++)
  {
      int u , k;

      cin>>u>>k;
      u--;
      k--;
      v[u].pb(k);
      v[k].pb(u);
  }

  for(int i=0 ; i<n ; i++)
  {
      cin>>a[i];
  }

  for(int i=0 ; i<n ; i++)
  {
      if(b[i]==a[i])
      {
          q.push(i);

      }
  }
  while(q.empty()==0)
  {
      int x=q.front();
       q.pop();
      javab[x]=1;
      for(int i:v[x])
      {
          b[i]+=1;
          if(b[i]==a[i])
          {
              q.push(i);

          }
      }
  }
  for(int i=0 ; i<n ; i++)
  {
        if(javab[i]==1)
            cout<<i+1<<" ";
}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , m;
vector < int > adj[maxn];
int a[maxn];
queue < int > q;
int cnt[maxn];
vector < int > ans;

int main(){
    migmig
    cin >> n >> m;
    for(int i = 0 ; i < m ; i ++){
		int u , v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
    for(int i = 1 ; i <= n ; i ++)
		cin >> a[i];
	for(int i = 1 ; i <= n ; i++)
		if(cnt[i] == a[i])
			q.push(i);
	while(!q.empty()){
		auto v = q.front();
		q.pop();
		cnt[v]++;
		for(auto u : adj[v]){
			cnt[u]++;
			if(cnt[u]==a[u])
				q.push(u);
		}
		ans.pb(v);
	}
	for(int i = 1 ; i <= n ; i ++)if(cnt[i]==a[i])dokme(-1);
    cout << ans.size() << endl;
    for(int i : ans)
		cout << i << ' ';
    return(0);
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int n, m; scanf("%d %d", &n, &m);
	vector<vector<int>> g(n);
	for (int i = 0; i < m; i++) {
		int u, v; scanf("%d %d", &u, &v);
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	queue<int> q;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i] == 0) q.emplace(i);
	}
	vector<int> s(n);
	vector<int> res;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		if (s[cur] != a[cur]) continue;
		res.emplace_back(cur);
		s[cur]++;
		for (auto nxt : g[cur]) {
			s[nxt]++;
			if (s[nxt] == a[nxt]) q.emplace(nxt);
		}
	}
	cout << res.size() << "\n";
	for (int i = 0; i < res.size(); i++) cout << res[i] + 1 << " \n"[i + 1 == res.size()];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  cout << "[";
  for(auto &i: v) cout << i << ", ";
  cout << "]" << endl;
  return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> g[n + 1];

  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y; x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  vector<int> v(n, 0);
  vector<int> ans;
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == v[i])
      q.push(i);
  }

  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (v[x] != a[x]) continue;

    ans.push_back(x);
    v[x]++;
    for (auto i: g[x]) {
      if (++v[i] == a[i])
        q.push(i);
    }
  }

  cout << ans.size() << endl;
  for (auto i: ans) cout << i + 1 << ' ';
  cout << endl;
  return 0;
}
/* Otha check long long
 * Complexity
 * Clarity
 */


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define debug(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  cout << "[";
  for(auto &i: v) cout << i << ", ";
  cout << "]" << endl;
  return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, pair<K, V> p) {
  os << "{" << p.first << ", " << p.second << "} ";
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> g[n + 1];

  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y; x--; y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }

  vector<int> v(n, 0);
  vector<int> ans;
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == v[i])
      q.push(i);
  }

  while (!q.empty()) {
    int x = q.front();
    if (v[x] != a[x]) continue;

    ans.push_back(x);
    q.pop();
    v[x]++;
    for (auto i: g[x]) {
      if (++v[i] == a[i])
        q.push(i);
    }
  }

  cout << ans.size() << endl;
  for (auto i: ans) cout << i + 1 << ' ';
  cout << endl;
  return 0;
}
/* Otha check long long
 * Complexity
 * Clarity
 */


#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

vi e[200000];
vb vis(200000);

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;

		e[u].push_back(v);
		e[v].push_back(u);
	}

	vi a(n + 1);
	for (int i = 1; i <= n; ++i)
		cin >> a[i];

	vi s(n + 1, 0);
	queue<int> q;
	for (int i = 1;i <= n; ++i)
		if (a[i] == s[i])
			q.push(i);

	vi sol;
	while (!q.empty()){
		int c = q.front();
		sol.push_back(c);
		q.pop();

		++s[c];
		for (auto& i : e[c]){
			++s[i];

			if (a[i] == s[i]){
				q.push(i);
			}
		}
	}

	cout << (int)sol.size() << '\n';
	for (auto& i : sol)
		cout << i << ' ';
	cout << '\n';
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> ans;
    queue<int> q;
    int n,m;
    cin>>n>>m;
    int counters[n];
    vector<int> graph[n];
    int array[m];
    for( int i = 0 ; i < m ; i++ )
    {
        int x,y;
        cin>>x>>y;
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for( int i = 0 ; i < n ; i++ )
    {
        cin>>array[i];
        counters[i]=0;
    }
    for(int i = 0 ; i < n ; i++)
    {
        if( array[i]==counters[i]  )
        {
            q.push(i);
        }
    }
    int counter=0;
    while( !q.empty() )
    {
        int t = q.front();
        if( counters[q.front()] == array[q.front()] )
        {
            counters[q.front()]++;
            counter++;
            ans.push_back(q.front()+1);
            for(int i = 0 ; i < graph[q.front()].size(); i++)
            {
                counters[ graph[q.front()][i] ]++;
            }
            q.pop();
        }
        for(int i = 0 ; i < graph[i].size()  ; i++)
        {
            if(counters[graph[t][i]] == array[i] )
            {
                q.push(i);
            }
            else
            {
                q.pop();
            }
        }
    }
    cout<<counter<<"\n";
    for(int i = 0 ; i < ans.size() ; i++)
        cout<<ans[i]<<" ";

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> ans;
    queue<int> q;
    int n,m;
    cin>>n>>m;
    int counters[n];
    vector<int> graph[n];
    int array[m];
    for( int i = 0 ; i < m ; i++ )
    {
        int x,y;
        cin>>x>>y;
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for( int i = 0 ; i < n ; i++ )
    {
        cin>>array[i];
        counters[i]=0;
    }
    for(int i = 0 ; i < n ; i++)
    {
        if( array[i]==counters[i]  )
        {
            q.push(i);
        }
    }
    int counter=0;
    while( !q.empty() )
    {

        int t = q.front();
        if( counters[q.front()] == array[q.front()] )
        {
            counters[q.front()]++;
            counter++;
            ans.push_back(q.front()+1);
            for(int i = 0 ; i < graph[q.front()].size(); i++)
            {
                counters[ graph[q.front()][i] ]++;
            }
            q.pop();
        }
        else
        {
            q.pop();
        }
        for(int i = 0 ; i < graph[t].size()  ; i++)
        {
            if(counters[graph[t][i]] == array[graph[t][i]] )
            {
                q.push(graph[t][i]);
            }
        }

    }
    cout<<counter<<"\n";
    for(int i = 0 ; i < ans.size() ; i++)
        cout<<ans[i]<<" ";

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> ans;
    queue<int> q;
    int n,m;
    cin>>n>>m;
    int counters[n];
    vector<int> graph[n];
    int array[m];
    for( int i = 0 ; i < m ; i++ )
    {
        int x,y;
        cin>>x>>y;
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
        //graph[x-1][graph[x-1].size()]=y-1;
        //graph[y-1][graph[y-1].size()]=x-1;
    }
    for( int i = 0 ; i < n ; i++ )
    {
        cin>>array[i];
        counters[i]=0;
    }
    for(int i = 0 ; i < n ; i++)
    {
        if( array[i]==counters[i]  )
        {
            q.push(i);
        }
    }
    int counter=0;
    while( !q.empty() )
    {
        if( counters[q.front()] == array[q.front()] )
        {
            counters[q.front()]++;
            counter++;
            ans.push_back(q.front()+1);
            for(int i = 0 ; i < graph[q.front()].size(); i++)
            {
                counters[ graph[q.front()][i] ]++;
            }
            q.pop();
        }
        for(int i = 0 ; i < graph[i].size()  ; i++)
        {
            if(counters[i] == array[i] )
            {
                q.push(i);
            }
            else
            {
                q.pop();
            }
        }
    }
    cout<<counter<<"\n";
    for(int i = 0 ; i < ans.size() ; i++)
        cout<<ans[i]<<" ";

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    vector<int> ans;
    queue<int> q;
    int n,m;
    cin>>n>>m;
    int counters[n];
    vector<int> graph[n];
    int array[n];
    for( int i = 0 ; i < m ; i++ )
    {
        int x,y;
        cin>>x>>y;
        graph[x-1].push_back(y-1);
        graph[y-1].push_back(x-1);
    }
    for( int i = 0 ; i < n ; i++ )
    {
        cin>>array[i];
        counters[i]=0;
    }
    for(int i = 0 ; i < n ; i++)
    {
        if( array[i]==counters[i]  )
        {
            q.push(i);
        }
    }
    int counter=0;
    while( !q.empty() )
    {

        int t = q.front();
        if( counters[q.front()] == array[q.front()] )
        {
            counters[q.front()]++;
            counter++;
            ans.push_back(q.front()+1);
            for(int i = 0 ; i < graph[q.front()].size(); i++)
            {
                counters[ graph[q.front()][i] ]++;
            }
            q.pop();
        }
        else
        {
            q.pop();
        }
        for(int i = 0 ; i < graph[t].size()  ; i++)
        {
            if(counters[graph[t][i]] == array[graph[t][i]] )
            {
                q.push(graph[t][i]);
            }
        }

    }
    cout<<counter<<"\n";
    for(int i = 0 ; i < ans.size() ; i++)
        cout<<ans[i]<<" ";

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
const int mxN = 10e5;
int N, M, arr[mxN + 5], arr2[mxN + 5];
int dist[mxN + 5];
vector<int> adj[mxN + 5];
vector<int> ans;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dist, -1, sizeof dist);

    cin >> N >> M;
    for (int i = 0, u, v; i < M; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    queue<int> q;
    for (int i = 1; i <= N; i++) {
        cin >> arr[i];
        if (arr[i] == 0) {
            dist[i] = 0;
            q.push(i);
        }
    }
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        if (arr2[u] == arr[u]) {
            ans.push_back(u);
            arr2[u]++;
            for (int v : adj[u]) {
                arr2[v]++;
                if (arr2[v] == arr[v]) {
                    q.push(v);
                }
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << (i == ans.size() - 1 ? "\n" : " ");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	vector <vl> adj(n + 1);
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a(n);
	set <ll> s;
	for (ll i = 0; i < n; i++)
		cin >> a[i];
	vl b(n);
	for (ll i = 0; i < n; i++)
		b[i] = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] >= b[i])
			s.insert(i);
	}
	vl ans;
	while (true) {
		int f = 0;
		for (auto it : s) {
			if (a[it] == b[it]) {
				//temp.insert(it);
				b[it]++;
				ans.pb(it + 1);
				for (auto j : adj[it]) {
					b[j]++;
				}
				f = 1;
				s.erase(it);
				break;
			}
		}
		if (f == 0)
			break;
	}
	cout << (ll)ans.size() << "\n";
	for (auto i : ans)
		cout << i << " ";
	cout << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, m;
	cin >> n >> m;
	vector <vl> adj(n + 1);
	for (ll i = 0; i < m; i++) {
		ll u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vl a(n);
	queue <ll> s;
	for (ll i = 0; i < n; i++)
		cin >> a[i];
	vl b(n);
	for (ll i = 0; i < n; i++)
		b[i] = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] == 0)
			s.push(i);
	}
	vl ans;
	while (!s.empty()) {
		int f = 0;
		ll it;
		it = s.front();
		s.pop();
		b[it]++;
		ans.pb(it + 1);
		for (auto j : adj[it]) {
			b[j]++;
			if (b[j] == a[j])
				s.push(j);
		}
	}
	cout << (ll)ans.size() << "\n";
	for (auto i : ans)
		cout << i << " ";
	cout << "\n";
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define Hkill(x)                    cout << x << endl; exit(0);
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; //1e9 + 7
const ld PI = 4 * atan((ld) 1);
ll W[MAXN], Z[MAXN];
set<ll> Q;
vector<ll> ans, adj[MAXN];

void bfs() {
    while (sz(Q)) {
        ll v = *Q.begin();
        Q.erase(Q.begin());
        ans.push_back(v);
        for (ll u : adj[v]) {
            if (++W[u] == Z[u]) {
                Q.insert(u);
            }
        }
    }
}

int main() {
    fast_io;
    set_random;
    ll n, m;
    cin >> n >> m;
    for (ll i = 1; i <= m; i++) {
        ll u, v;
        cin >> u >> v;
        adj[v].push_back(u);
        adj[u].push_back(v);
    }
    for (ll i = 1; i <= n; i++) {
        cin >> Z[i];
        if (Z[i] == 0) Q.insert(i);
    }

    bfs();
    cout << sz(ans) << endl;
    for (ll x : ans)
        cout << x << sep;
    return 0;
}


 //Dragon_warrior7(IITK)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define inf 1000000000000000000
#define pll pair<ll, ll>
#define vll vector<ll>
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define Lets_be_precise cout<<fixed<<setprecision(10)
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
inline void read(vector<ll> &v);
inline ll max(ll a,ll b);
inline ll min(ll a,ll b);
inline ll gcd(ll a ,ll b);
int val[MAXN];
vll v[MAXN];
int value[MAXN];
queue<int> q;
void solveforthiscase(const int & test)
{
cin>>n>>m;
vector<int> ans;
while(m--)
{
  cin>>a>>b;
  v[a].pb(b);v[b].pb(a);
}
for(int i=1;i<=n;i++)
{cin>>val[i];if(!val[i])q.push(i);}
while(!q.empty())
{
  int f=q.front();q.pop();ans.pb(f);value[f]++;
  for(const auto &x:v[f])
  {
    value[x]++;
    if(value[x]==val[x])
    q.push(x);
  }
}
cout<<ans.size()<<'\n';
for(const auto &x:ans)
cout<<x<<' ';
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    Lets_be_precise;
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    clock_t start, end;
    start = clock();
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
     end = clock();
    long double time_taken = (long double)(end - start) /(long double)(CLOCKS_PER_SEC);
    cerr << "Time taken by program is : "<< (long double)time_taken*1000<< " milisec ";
}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
inline void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N],cnt[N];
bool vis[N];
vector < int > v[N];
vector < int > Ans;
set < pair < int, int > > st;

int main()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1; i<=n; i++)   cin >> a[i], st.insert({a[i], i});
    while(st.size() && st.begin()->first <= 0)
    {
        if(st.begin()->first < 0)
        {
            st.erase(st.begin());
            continue;
        }
        if(st.begin()->first == 0)
        {
            int Node = st.begin()->second;
            vis[Node] = true;
            Ans.push_back(Node);
            st.erase(st.begin());
            for(auto j : v[Node])  st.erase({a[j] - cnt[j], j});
            cnt[Node]++;
            for(auto j : v[Node])
            {
                cnt[j]++;
                if(!vis[j])  st.insert({a[j] - cnt[j], j});
            }
        }
    }
    for(int i=1; i<=n; i++)  if(a[i] == cnt[i])  return 0 * puts("-1");
    cout << Ans.size() << endl;
    for(auto x : Ans)  cout << x << " ";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N];
bool Dif[N * 2],vis[N],vis2[N];
vector < int > v[N];
vector < int > Nodes, Ans;

void DFS(int x)
{
    vis[x] = true;
    if(a[x] <= x)  Dif[x - a[x]] = true;
    Nodes.push_back(x);

    for(auto j : v[x])  if(!vis[j])  DFS(j);
}

void DFS2(int x)
{
    vis2[x] = true;
    if(a[x] <= x)  Dif[x - a[x]] = false;
    for(auto j : v[x])  if(!vis2[j])  DFS2(j);
}

int main()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1;i<=n;i++)  cin >> a[i];
    for(int i=1; i<=n; i++)
    {
        if(!vis[i])
        {
            DFS(i);
            for(int j = 0; j<=n; j++)
            {
                if(Dif[j])  Ans.push_back(Nodes[Nodes.size() - 1]), Nodes.pop_back();
                else   break;
            }
            Nodes.clear();
            DFS2(i);
        }
    }
    cout << Ans.size() << endl;
    for(auto x : Ans)  cout << x << " ";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N],cnt[N];
bool vis[N];
vector < int > v[N];
vector < int > Ans;
vector < pair < int , int > > Dif;

void DFS(int x)
{
    vis[x] = true;
    bool check = false;
    if(a[x] == cnt[x])  check = true;
    for(auto j : v[x])  if(a[j] == cnt[j])  check = true;
    if(check)  {
            Ans.push_back(x);
            for(auto j : v[x])  cnt[j]++;
            cnt[x]++;
    }
    for(auto j : v[x])  if(!vis[j])  DFS(j);
}

int main()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1; i<=n; i++)   cin >> a[i], Dif.push_back({a[i], i});
    sort(Dif.begin(), Dif.end() , greater < pair < int , int > > ());
    for(int i=0; i<Dif.size(); i++)
    {
        if(!vis[Dif[i].second])  DFS(Dif[i].second);
    }
    for(int i=1; i<=n; i++)  if(a[i] == cnt[i])  return 0 * puts("-1");
    cout << Ans.size() << endl;
    for(auto x : Ans)  cout << x << " ";
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;
int a[N],cnt[N];
bool vis[N];
vector < int > v[N];
vector < int > Ans;
vector < pair < int , int > > Dif;

void DFS(int x)
{
    vis[x] = true;
    if(a[x] == cnt[x])
    {
        Ans.push_back(x);
        cnt[x]++;
        for(auto j : v[x])  cnt[j]++;
    }
    for(auto j : v[x])  if(!vis[j])  DFS(j);
}

int main()
{
    int n,m;
    cin >> n >> m;
    while(m--)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=1; i<=n; i++)   cin >> a[i], Dif.push_back({a[i], i});
    sort(Dif.begin(), Dif.end());
    for(int i=0; i<Dif.size(); i++)
    {
        if(!vis[Dif[i].second])  DFS(Dif[i].second);
    }
    for(int i=1; i<=n; i++)  if(a[i] == cnt[i])  return 0 * puts("-1");
    cout << Ans.size() << endl;
    for(auto x : Ans)  cout << x << " ";
    return 0;
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, m, a[N];
vector<int> g[N];

void code() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> val(n + 1, 0);
    queue<int> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (val[i] == a[i]) q.push(i);
    }

    vector<int> ans;
    while (!q.empty()) {
        int x = q.front();
        ans.push_back(x);
        q.pop();

        for (auto i : g[x]) {
            val[i]++;
            if (val[i] == a[i]) {
                q.push(i);
            }
        }
    }

    cout << ans.size() << "\n";
    for (auto i : ans) cout << i << " "; cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}


#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

int n, m, a[N];
vector<int> g[N];

void code() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int st = -1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (i == a[i]) st = i;
    }

    if (st == -1) {
        cout << "0\n";
        return;
    }

    queue<int> q;
    q.push(st);

    vector<int> ans;
    while (!q.empty()) {
        int x = q.front();
        ans.push_back(x);
        q.pop();

        for (auto i : g[x]) {
            a[i]++;
            if (a[i] == i) {
                q.push(i);
            }
        }
    }

    cout << ans.size() << "\n";
    for (auto i : ans) cout << i << " "; cout << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define p pair
#define mp make_pair

int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>>adj(n);
    for(int i=0;i<m;++i){
        int a,b;cin>>a>>b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    vector<int>a(n);
    vector<int>b(n,0);
    vector<int>ans;
    for(int i=0;i<n;++i)
        cin>>a[i];
    for(int i=0;i<n;++i){
        if(a[i]==b[i]){
            ans.push_back(i);
            ++b[i];
            for(int j=0;j<adj[i].size();++j)
                ++b[adj[i][j]];
            i=-1;
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();++i)
        cout<<ans[i]+1<<" ";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define p pair
#define mp make_pair

int main() {
    int n,m;
    cin>>n>>m;
    vector<vector<int>>adj(n);
    for(int i=0;i<m;++i){
        int a,b;cin>>a>>b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }
    vector<int>a(n);
    vector<int>b(n,0);
    vector<int>ans;
    for(int i=0;i<n;++i)
        cin>>a[i];

    queue<int>q;
    for(int i=0;i<n;++i){
        if(a[i]==b[i])
            q.push(i);
    }
    while(!q.empty()){
        int u=q.front();
        q.pop();
        ans.push_back(u);
        ++b[u];
        for(int j=0;j<adj[u].size();++j){
            ++b[adj[u][j]];
            if(b[adj[u][j]]==a[adj[u][j]])
                q.push(adj[u][j]);
        }

    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();++i)
        cout<<ans[i]+1<<" ";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
#define _for(i,a,b) for(int i=(a);i<(b);++i)
#define ms(a) memset(a,0,sizeof(a))
#define ms_inf(a) memset(a,0x3f,sizeof(a))
#define ms_ninf(a) memset(a,0xcf,sizeof(a))
#define pb push_back
#define mp make_pair
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
//#define lc (o<<1)
//#define rc (o<<1|1)
//#include<ext/pb_ds/priority_queue.hpp>
//typedef __gnu_pbds::priority_queue<no> heap;  //��ƫ��
typedef long long ll;
typedef unsigned long long ull;
ull MOD=212370440130137957ll;
int mod=998244353;
ll INF=1e18;
const int maxn=2e5+10;
const int maxl=1e5+10;
const double PI=acos(-1.0);
const double eps=1e-8;
bool done[maxn];
int a[maxn],b[maxn];
queue<int>q;
vector<int>g[maxn];int n,m;
vector<int>ans;
void bfs(int i)
{
	if(done[i])return;
	ans.pb(i);
	++b[i];
	for(auto&w:g[i])
	{
		if(++b[w]==a[w])q.push(w);
	}
}
int main()
{
	fast;cin>>n>>m;_for(t,0,m)
	{
		int u,v;cin>>u>>v;g[u].pb(v),g[v].pb(u);
	}
	_for(t,1,n+1)cin>>a[t];_for(t,1,n+1)if(!a[t])q.push(t);
	while(!q.empty())
	{
		int c=q.front();q.pop();
		bfs(c);
	}
	cout<<ans.size()<<"\n";for(auto&w:ans)cout<<w<<" ";
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005;
bool f[maxn][maxn] = {0};
int A[maxn], len[maxn], lcnt;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T, N;
	cin >> T;
	for (int cas = 1; cas <= T; ++cas) {
		cin >> N;
		for (int i = 1; i <= 2 * N; ++i) {
			cin >> A[i];
		}
		memset(f, 0, sizeof(f));
		lcnt = 0;
		int lastmax = 0;
		for (int i = 1; i <= 2 * N; ++i) {
			if (A[i] > lastmax) len[++lcnt] = 1, lastmax = A[i];
			else ++len[lcnt];
		}
		f[0][0] = true;
		for (int i = 1; i <= lcnt; ++i) {
			for (int j = 0; j <= N; ++j) {
				f[i][j] = f[i-1][j];
				if (j >= len[i]) f[i][j] |= (f[i - 1][j - len[i]]);
				//cerr << f[i][j] << " ";
			}
			//cerr << endl;
		}
		//cerr << endl;
		if (f[lcnt][N]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2050;
typedef pair<int, int> PII;
bitset<MAXN> dp;
int n, a[MAXN << 1];
int main() {
#ifdef TEST
	freopen("input.txt", "r", stdin);
#endif
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		for (int i = 0; i < n + n; ++i) {
			scanf("%d", &a[i]);
		}
		dp.reset();
		dp.set(0);
		for (int i = 0; i < n + n;) {
			int j = i;
			while (a[j] <= a[i] && j < n + n) j++;
			dp |= dp << (j - i);
			i = j;
		}
		puts(dp[n] ? "YES" : "NO");
	}
	return 0;
}

/*
01011
11011
00100
10100
10100
00100
01100
01100

*/


#include<bits/stdc++.h>
using namespace std;
const int N = 4e3 + 10;
const int inf = 0x7f7f7f7f;

int p[N],a[N];
int dp[N];

void solve(){
    int n,cnt = 0;
    scanf("%d",&n);
    p[0] = inf;
    for(int i = 1;i <= 2*n;i++){
        scanf("%d",p+i);
    }
    int sum = 1,x = p[1];
    for(int i = 2;i <= 2*n;i++){
        if(p[i] < x){
            sum++;
        }else {
            a[++cnt] = sum;
            sum = 1;
            x = p[i];
        }
    }
    a[++cnt] = sum;
    memset(dp,0,sizeof dp);
    for(int i = 1;i <= cnt;i++){
        for(int j = n;j >= a[i];j--){
            dp[j] = max(dp[j],dp[j-a[i]]+a[i]);
        }
    }
    if(dp[n] == n){
        printf("YES\n");
    }else {
        printf("NO\n");
    }
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
int T,n,p,cnt[4001],now,len;
bool f[2001];
inline int read()
{
	char ch=getchar();
	while(ch<'0'||ch>'9')
	    ch=getchar();
	int res=0;
	while(ch>='0'&&ch<='9')
	{
		res=res*10+ch-'0';
		ch=getchar();
	}
	return res;
}
int main()
{
	T=read();
	while(T--)
	{
		n=read();
		for(register int i=1;i<=len;++i)
		    cnt[i]=0;
		now=len=0;
		for(register int i=1,m=n<<1;i<=m;++i)
		{
			p=read();
			if(p>now)
			{
				cnt[++len]=1;
				now=p;
			}
			else
			    ++cnt[len];
		}
		memset(f,0,sizeof(f));
		f[0]=1;
		for(register int i=1;i<=len;++i)
		{
		    for(register int j=n;j>=cnt[i];--j)
		    	f[j]|=f[j-cnt[i]];
		    if(f[n])
		        break;
		}
		if(f[n])
		    puts("YES");
		else
		    puts("NO");
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int t,n;
int a[4005];
int b[4005],k;
int dp[2005][2005];

int main ()
{
    cin>>t;
    while(t--)
    {
        k=1;int maxx=0,maxpos;
        cin>>n;
        for(int i=1;i<=2*n;i++){cin>>a[i];if(a[i]>maxx)maxx=a[i],maxpos=i;}
        if(maxpos<n)
        {
            cout<<"NO"<<endl;
            continue;
        }
        for(int i=1;i<=2*n;i++)
        {
            int j=i;b[k]=1;
            while(j+1<=2*n&&a[j+1]<=a[i])
                j++,b[k]++;
            i=j;
            k++;
        }
        dp[0][0]=1;
        for(int i=1;i<k;i++)
        {
            for(int j=0;j<=n;j++)
            {
                dp[i][j]=0;
                if(j>=b[i])
                    dp[i][j]|=dp[i-1][j-b[i]];
                dp[i][j]|=dp[i-1][j];
            }
        }
        if(dp[k-1][n])cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int a[4001];
bool b[4001];
int w[4002];
int p[4001];
bool f[4001];
int main()
{
	//freopen("split.in","r",stdin);
	//freopen("split.out","w",stdout);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		memset(f,0,sizeof(f));
		memset(b,0,sizeof(b));
		int n;
		cin>>n;
		int suma=n,sumb=n;
		n*=2;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			w[a[i]]=i;
		}
		int last=n+1;
		w[n+1]=n+1;
		int tot=0;
		for(int i=n;i>=1;i--)
		{
			if(!b[i])
			{
				for(int j=w[i];j<=w[last];j++)
				{
					b[a[j]]=1;
				}
				p[++tot]=w[last]-w[i];
				last=i;
			}
		}
		for(int i=1;i<=tot;i++)
		{
			for(int j=n>>1;j>=1;j--)
			{
				if(f[max(0,j-p[i])]||f[j])
				{
					f[j]=1;
				}
			}
			f[p[i]]=1;
		}
		if(f[n>>1])
		{
			cout<<"YES"<<endl;
		}
		else
		{
			cout<<"NO"<<endl;
		}
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 4000 + 10;

int T, n, a[N];
int now, f[2][N], g[N] , tot;

void Work(){
	scanf("%d", &n); n *= 2;
	for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	memset(f, 0, sizeof(f)); tot = 0;
	for(int i = 1; i <= n; ++ i){
		int pos = i;
		while(a[pos + 1] < a[i] && pos < n) pos ++;
		g[++ tot] = pos - i + 1;
		i = pos;
	}
	f[0][2000] = 1; now = 1;
	for(int i = 1; i <= tot; ++ i, now ^= 1){
		for(int j = g[i]; j <= 4000 - g[i]; ++ j){
			f[now][j] = f[now ^ 1][j - g[i]] | f[now ^ 1][j + g[i]];
		}
	}
	now ^= 1;
	if(f[now][2000]) printf("YES\n");
	else printf("NO\n");
}

int main()
{
	scanf("%d", &T);
	while(T --) Work();
	return 0;
}


#include <bitset>
int h[4040];
std::bitset<2000>f;
int read()
{
	int x = 0;
	char c = getchar();
	while(!isdigit(c))
	{
		c = getchar();
	}
	while(isdigit(c))
	{
		x = x * 10 + c - 48;
		c = getchar();
	}
	return x;
}
int main()
{
    int T = read();
    while (T--)
    {
    	f.reset();
    	f[0] = 1;
        int n = read(), tot = 0, cnt = 0, cmax = 0;
        for (int i = 1; i <= n << 1; ++i)
        {
        	int p = read();
        	if(p > cmax)
        	{
        		if(cmax)
        		{
        			h[++cnt] = tot;
				}
        		tot = 1;
        		cmax = p;
			}
			else
			{
				tot++;
			}
		}
		h[++cnt] = tot;
		for (int i = 1; i <= cnt; ++i)
		{
			f |= (f << h[i]);
			for (int j = n; j >= h[i]; --j)
			{
				f[j] = f[j] | f[j - h[i]];
			}
		}
		puts(f[n] ? "YES" : "NO");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 4000 + 10;

int T, n, a[N];
int now, f[2][N], g[N] , tot;

void Work(){
	scanf("%d", &n); n *= 2;
	for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	memset(f, 0, sizeof(f)); tot = 0;
	for(int i = 1; i <= n; ++ i){
		int pos = i;
		while(a[pos + 1] < a[i] && pos < n) pos ++;
		g[++ tot] = pos - i + 1;
		i = pos;
	}
	f[0][2000] = 1; now = 1;
	for(int i = 1; i <= tot; ++ i, now ^= 1){
		for(int j = 0; j <= 4000; ++ i) f[now][j] = 0;
		for(int j = g[i]; j <= 4000 - g[i]; ++ j){
			f[now][j] = f[now ^ 1][j - g[i]] | f[now ^ 1][j + g[i]];
		}
	}
	now ^= 1;
	if(f[now][2000]) printf("YES\n");
	else printf("NO\n");
}

int main()
{
	scanf("%d", &T);
	while(T --) Work();
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int t,n,maxx,tmp,cnt,maxpos,tot;
int len[4010],a[4010];
int dp[4010][2010];//dp[i][j]表示前i个物品能否装满体积为j的背包。
char *p1,*p2,buf[100000];
#define nc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
int read()
{
    int x=0,f=1;
    char ch=nc();
    while(ch<'0'||ch>'9')
        if(ch=='-')
            f=-1,ch=nc();
    while(ch>='0'&&ch<='9')
        x=x*10+ch-48,ch=nc();
    return x*f;
}
int main()
{
    t=read();
    while(t--)
    {
        tot=0,maxx=0;
        n=read();
        for(int i=1;i<=2*n;i++)
        {
            a[i]=read();
            if(a[i]>maxx)
                maxx=a[i],maxpos=i;
            if(i==1)
                tmp=a[i],cnt=1;
            if(a[i]>tmp)
                len[++tot]=cnt,tmp=a[i],cnt=1;
            if(a[i]<tmp)
                cnt++;
        }
        if(maxpos<n)
        {
            puts("NO");
            continue;
        }
        len[++tot]=cnt;
        dp[0][0]=1;
        for(int i=1;i<=tot;i++)
            for(int j=0;j<=n;j++)
            {
                dp[i][j]=0;
                if(j>=len[i])
                    dp[i][j]|=dp[i-1][j-len[i]];
                dp[i][j]|=dp[i-1][j];
            }
        if(dp[tot][n])
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int MAXN = 1e6+7;
const int INF = 1e9+7;
const int MOD=  1e9+7;
#define LL long long
#define pb push_back
#define fi first
#define se second
typedef pair<int ,int > pii;
typedef vector<int > pi;
struct as{
	int l,r,sz;
	int maxx;
}a[maxn];
int b[maxn];
pii dp[2][maxn];
int main()
{
	int i,j,n,m,t,z;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int pos = 0;
		for(i=1;i<=2*n;i++)
		{
			scanf("%d",&b[i]);
		}
		b[0]=100000;
		int l=1,r=1;
		int maxx=0;
		for(i=1;i<=2*n;i++)
		{
			if(b[i]>b[i-1])
			{
				r=i-1;
				pos++;
				a[pos].l=l;
				a[pos].r=r;
				a[pos].maxx=maxx;
				a[pos].sz=r-l+1;
				r=l=i;
				maxx=b[i];
			}
			else
			{
				maxx=max(maxx,b[i]);
			}
		}
		r=2*n;
		pos++;
		a[pos].l=l;
		a[pos].r=r;
		a[pos].sz=r-l+1;
		a[pos].maxx=maxx;
		for(i=1;i<=pos;i++)
		{
			for(j=0;j<=n;j++)
			{
				if(j==0||dp[0][j].fi!=0||dp[0][j].se!=0)
				{
					if(a[i].maxx>dp[0][j].fi&&j+a[i].sz<=n)
					{
						dp[1][j+a[i].sz].fi=dp[0][j].fi;
						dp[1][j+a[i].sz].se=max(a[i].maxx,dp[0][j].se);
					}
					if(a[i].maxx>dp[0][j].se)
					{
						dp[1][j].fi=max(a[i].maxx,dp[0][j].fi);
						dp[1][j].se=dp[0][j].se;
					}
					dp[0][j].fi=dp[0][j].se=0;
				}
			}
			swap(dp[0],dp[1]);
		}
		if(dp[0][n].fi!=0||dp[0][n].se!=0)
		{
			puts("YES");
		}
		else
		puts("NO");
		for(i=0;i<=n;i++)
		{
			dp[0][i].fi=dp[0][i].se=dp[1][i].fi=dp[1][i].se=0;
		}
	}
	return 0;
 }


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
const int MAXN = 1e6+7;
const int INF = 1e9+7;
const int MOD=  1e9+7;
#define LL long long
#define pb push_back
#define fi first
#define se second
typedef pair<int ,int > pii;
typedef vector<int > pi;
struct as{
	int l,r,sz;
	int maxx;
}a[maxn];
int b[maxn];
pii dp[2][maxn];
int main()
{
	int i,j,n,m,t,z;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		int pos = 0;
		for(i=1;i<=2*n;i++)
		{
			scanf("%d",&b[i]);
		}
		b[0]=100000;
		int l=1,r=1;
		int maxx=0;
		for(i=1;i<=2*n;i++)
		{
			pos++;
			l=r=i;
			a[pos].l=l;
			a[pos].r=r;
			a[pos].sz=r-l+1;
			a[pos].maxx=b[i];
		}
		for(i=0;i<=n;i++)
		{
			dp[0][i].fi=dp[0][i].se=dp[1][i].fi=dp[1][i].se=maxn;
		}
		dp[0][0].fi=dp[0][0].se=0;
		for(i=1;i<=pos;i++)
		{
			for(j=0;j<=n;j++)
			{
				if(dp[0][j].fi!=maxn||dp[0][j].se!=maxn)
				{
					if(dp[0][j].fi!=maxn)
					{
						dp[1][j+1].fi=min(max(a[i].maxx,dp[0][j].fi),dp[1][j+1].fi);

						if(a[i].maxx>dp[0][j].fi)
						dp[1][j].se=min(a[i].maxx,dp[1][j].se);
					}
					if(dp[0][j].se!=maxn)
					{
						if(a[i].maxx>dp[0][j].se)
						dp[1][j+1].fi=min(a[i].maxx,dp[1][j+1].fi);

						dp[1][j].se=min(max(a[i].maxx,dp[0][j].se),dp[1][j].se);
					}
					dp[0][j].fi=dp[0][j].se=maxn;
				}
			}
			swap(dp[0],dp[1]);
			for(j=0;j<=n;j++)
			{
				dp[1][j].se=dp[1][j].fi=maxn;
			}
		}
		if(dp[0][n].fi!=maxn||dp[0][n].se!=maxn)
		{
			puts("YES");
		}
		else
		puts("NO");
		for(i=0;i<=n;i++)
		{
			dp[0][i].fi=dp[0][i].se=dp[1][i].fi=dp[1][i].se=maxn;
		}
	}
	return 0;
 }
 /*
10
4
3 2 6 1 5 7 8 4
 */


#include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
using namespace std;

const int maxn = 2005;
int dp[maxn][maxn], a[maxn << 1], pos[maxn << 1], N;

int solve(int x, int y) {
    if (x > N || y > N) return 0;
    if (x == N && y == N) return 1;
    if (dp[x][y] != -1) return dp[x][y];
    int nxt = x + y + 1;
    int loc = pos[nxt];
    return dp[x][y] = solve(x + (loc - nxt + 1), y) | solve(x, y + (loc - nxt + 1));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int testcase;
    cin >> testcase;
    while (testcase--) {
        cin >> N;
        rep(i, 1, 2 * N) cin >> a[i];
        rep(i, 0, N) rep(j, 0, N) dp[i][j] = -1;
        rep(i, 1, 2 * N) {
            int init = a[i];
            pos[i] = 2 * N;
            rep(j, i + 1, 2 * N) {
                if (a[j] > init) {
                    pos[i] = j - 1;
                    break;
                }
            }
        }
        int res = solve(0, 0);
        cout << ((res) ? "YES" : "NO") << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
using namespace std;

const int maxn = 2005;
int dp[maxn][maxn], a[maxn << 1], pos[maxn << 1], N;

int solve(int x, int y) {
    if (dp[x][y] != -1) return dp[x][y];
    if (x > N || y > N) return 0;
    if (x == N && y == N) return 1;
    int nxt = x + y + 1;
    int loc = pos[nxt];
    return dp[x][y] = solve(x + (loc - nxt + 1), y) | solve(x, y + (loc - nxt + 1));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int testcase;
    cin >> testcase;
    while (testcase--) {
        cin >> N;
        rep(i, 1, 2 * N) cin >> a[i];
        rep(i, 0, N) rep(j, 0, N) dp[i][j] = -1;
        rep(i, 1, 2 * N) {
            int init = a[i];
            pos[i] = 2 * N;
            rep(j, i + 1, 2 * N) {
                if (a[j] > init) {
                    pos[i] = j - 1;
                    break;
                }
            }
        }
        int res = solve(0, 0);
        cout << ((res) ? "YES" : "NO") << "\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
using namespace std;

const int maxn = 2005;
int dp[maxn][maxn], a[maxn << 1], pos[maxn << 1], N;

int solve(int x, int y) {
    if (x > N || y > N) return 0;
    if (x == N && y == N) return 1;
    int nxt = x + y + 1;
    int loc = pos[nxt];
    return solve(x + (loc - nxt + 1), y) | solve(x, y + (loc - nxt + 1));
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int testcase;
    cin >> testcase;
    while (testcase--) {
        cin >> N;
        rep(i, 1, 2 * N) cin >> a[i];
        rep(i, 0, N) rep(j, 0, N) dp[i][j] = -1;
        rep(i, 1, 2 * N) {
            int init = a[i];
            pos[i] = 2 * N;
            rep(j, i + 1, 2 * N) {
                if (a[j] > init) {
                    pos[i] = j - 1;
                    break;
                }
            }
        }
        int res = solve(0, 0);
        cout << ((res) ? "YES" : "NO") << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
#define RI(i) scanf("%lld", &i);

int main(int argc, char *argv[]) {
  i64 t, T;
  RI(T);
  REP(0, T, t) {
    i64 n, i;
    RI(n);
    vi p(2*n);
    REP(0, 2*n, i) {
      RI(p[i]);
    }

    set<i64, greater<i64>> r;
    REP(0, 2*n, i) {
      r.insert(i+1);
    }

    multiset<i64, greater<i64>> nums;
    i64 cur = n * 2;
    i = n * 2 - 1;
    while(i >= 0) {
      if(p[i] == *r.begin()) {
	nums.insert(cur - i);
	cur = i;
      }
      r.erase(r.find(p[i]));
      i--;
    }
    nums.insert(cur);

    i64 c0 = 0, c1 = 0;
    for(auto c: nums) {
      if(c0 < c1) {
	c0 += c;
      }
      else {
	c1 += c;
      }
    }
    if(c0 == n) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
#define RI(i) scanf("%lld", &i);

int main(int argc, char *argv[]) {
  i64 t, T;
  RI(T);
  REP(0, T, t) {
    i64 n, i;
    RI(n);
    vi p(2*n);
    REP(0, 2*n, i) {
      RI(p[i]);
    }

    set<i64, greater<i64>> r;
    REP(0, 2*n, i) {
      r.insert(i+1);
    }

    multiset<i64, greater<i64>> nums;
    i64 cur = n * 2;
    i = n * 2 - 1;
    while(i >= 0) {
      if(p[i] == *r.begin()) {
	nums.insert(cur - i);
	cur = i;
      }
      r.erase(r.find(p[i]));
      i--;
    }
    nums.insert(cur);

    vi f(n+1, 0);
    f[0] = 1;
    for(auto c: nums) {
      for(i=n;i>=0;i--) {
	if(f[i] == 1 && i + c <= n) {
	  f[i+c] = 1;
	}
      }
    }

    /*
    REP(0, n+1, i) {
      cout << f[i] << " ";
    }
    cout << endl;
    */

    if(f[n] == 1) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 4005
#define ll long long

void DBG() {
    cerr << "]\n";
}
template <class H, class... T> void DBG(H h, T... t) {
    cerr << h;
    if (sizeof...(t)) {
        cerr << ", ";
    }
    DBG(t...);
}
#define _DEBUG
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int tt, n, a[maxn], vis[maxn];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> tt;
    while (tt--) {
        cin >> n;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= 2 * n; i++) {
            cin >> a[i];
        }
        int la = 2 * n + 1;
        vector<int> vec;
        for (int i = 2 * n; i >= 1; i--) {
            int mi = i;
            for (int j = i; j >= 1; j--) {
                if (a[j] > a[mi])
                    mi = j;
            }
            vec.push_back(la - mi);
            la = i = mi;
        }

        for (int i = 0; i < vec.size(); i++) {
            for (int j = n - vec[i]; j >= 1; j--)
                if (vis[j])
                    vis[j + vec[i]] = 1;

            vis[vec[i]] = 1;
        }
        cout << (vis[n] ? "YES\n" : "NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 4005
#define ll long long

void DBG() {
    cerr << "]\n";
}
template <class H, class... T> void DBG(H h, T... t) {
    cerr << h;
    if (sizeof...(t)) {
        cerr << ", ";
    }
    DBG(t...);
}
#define _DEBUG
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define reg register
int tt, n, a[maxn], vis[maxn];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> tt;
    while (tt--) {
        cin >> n;
        for (reg int i = 1; i <= 2 * n; i++) {
            vis[i] = 0;
            cin >> a[i];
        }
        int la = 2 * n + 1;
        vector<int> vec;
        for (reg int i = 2 * n; i >= 1; i--) {
            int mi = i;
            for (int j = i; j >= 1; j--) {
                if (a[j] > a[mi])
                    mi = j;
            }
            vec.push_back(la - mi);
            la = i = mi;
        }

        for (reg int i = 0; i < vec.size(); i++) {
            for (reg int j = n - vec[i]; j >= 1; j--)
                if (vis[j])
                    vis[j + vec[i]] = 1;

            vis[vec[i]] = 1;
        }
        cout << (vis[n] ? "YES\n" : "NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define maxn 2005

void DBG() {
    cerr << "]\n";
}
template <class H, class... T> void DBG(H h, T... t) {
    cerr << h;
    if (sizeof...(t)) {
        cerr << ", ";
    }
    DBG(t...);
}
#define _DEBUG
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int tt, n, a[maxn], vis[maxn];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> tt;
    while (tt--) {
        cin >> n;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= 2 * n; i++) {
            cin >> a[i];
        }
        int la = 2 * n + 1;
        vector<int> vec;
        for (int i = 2 * n; i >= 1; i--) {
            int mi = i;
            for (int j = i; j >= 1; j--) {
                if (a[j] > a[mi])
                    mi = j;
            }
            vec.push_back(la - mi);
            la = i = mi;
        }

        for (int i = 0; i < vec.size(); i++) {
            for (int j = n - vec[i]; j >= 1; j--)
                if (vis[j])
                    vis[j + vec[i]] = 1;

            vis[vec[i]] = 1;
        }
        cout << (vis[n] ? "YES\n" : "NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 2005
#define ll long long

void DBG() {
    cerr << "]\n";
}
template <class H, class... T> void DBG(H h, T... t) {
    cerr << h;
    if (sizeof...(t)) {
        cerr << ", ";
    }
    DBG(t...);
}
#define _DEBUG
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

int tt, n, a[maxn], vis[maxn];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> tt;
    while (tt--) {
        cin >> n;
        memset(vis, 0, sizeof(vis));
        for (int i = 1; i <= 2 * n; i++) {
            cin >> a[i];
        }
        int la = 2 * n + 1;
        vector<int> vec;
        for (int i = 2 * n; i >= 1; i--) {
            int mi = i;
            for (int j = i; j >= 1; j--) {
                if (a[j] > a[mi])
                    mi = j;
            }
            vec.push_back(la - mi);
            la = i = mi;
        }

        for (int i = 0; i < vec.size(); i++) {
            for (int j = n - vec[i]; j >= 1; j--)
                if (vis[j])
                    vis[j + vec[i]] = 1;

            vis[vec[i]] = 1;
        }
        cout << (vis[n] ? "YES\n" : "NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define maxn 4005

#define reg register
inline int read(){
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=(s<<3)+(s<<1)+ch-'0';
        ch=getchar();
    }
    return s*f;
}
int tt, n, a[maxn], vis[maxn];

int main() {
    tt = read();
    while (tt--) {
        n = read();
        for (reg int i = 1; i <= 2 * n; i++) {
            vis[i] = 0;
            a[i] = read();
        }
        int la = 2 * n + 1;
        vector<int> vec;
        for (reg int i = 2 * n; i >= 1; i--) {
            int mi = i;
            for (int j = i; j >= 1; j--) {
                if (a[j] > a[mi])
                    mi = j;
            }
            vec.push_back(la - mi);
            la = i = mi;
        }

        for (reg int i = 0; i < vec.size(); i++) {
            for (reg int j = n - vec[i]; j >= 1; j--)
                if (vis[j])
                    vis[j + vec[i]] = 1;

            vis[vec[i]] = 1;
        }
        puts(vis[n] ? "YES" : "NO");
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t,n;
int p[4005],s[4005];
int dp[2005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		n*=2;
		for(int i=1;i<=n;i++)
		cin>>p[i];
		int last=1,tmp=1,tot=0;;
		for(int i=2;i<=n;i++)
		{
			if(p[i]<p[last])
			{
				tmp++;
			}
			else
			{
				s[++tot]=tmp;
				tmp=1;
				last=i;
			}
		}
		s[++tot]=tmp;
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		n=n>>1;
		for(int i=1;i<=tot;i++)
		{
			for(int j=n;j>=1;j--)
			{
				if(dp[j-s[i]])
				dp[j]=1;
			}
		}
		if(dp[n])
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t,n;
int p[4005],s[4005];
int dp[2005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		n*=2;
		for(int i=1;i<=n;i++)
		cin>>p[i];
		int last=1,tmp=1,tot=0;;
		for(int i=2;i<=n;i++)
		{
			if(p[i]<p[last])
			{
				tmp++;
			}
			else
			{
				s[++tot]=tmp;
				tmp=1;
				last=i;
			}
		}
		s[++tot]=tmp;
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		n=n>>1;
		for(int i=1;i<=tot;i++)
		{
			for(int j=n;j>=1;j--)
			{
				if(j-s[i]>=0&&dp[j-s[i]])
				dp[j]=1;
			}
		}
		if(dp[n])
		cout<<"YES"<<endl;
		else
		cout<<"NO"<<endl;
	}
	return 0;
}


#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep_1(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
inline int read()
{
	int num=0, w=0;
	char ch=0;
	while (!isdigit(ch))
	{
		w|=ch=='-';
		ch = getchar();
	}
	while (isdigit(ch))
	{
		num = (num<<3) + (num<<1) + (ch^48);
		ch = getchar();
	}
	return w? -num: num;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=2e6+10;
int a[N];
	int w[N];
int dp[2020];
void solve()
{
	int n;
	memset(dp,0,sizeof  dp);
	cin>>n;
	for(int i=1; i<=2*n; i++)
		cin>>a[i];
	int now=a[1];
	int  b[2];
	b[0]=0;
	b[1]=0;
	int flag=0;
	int num=1;
	int cnt=0;
	for(int i=2; i<=2*n; i++)
	{
		if(a[i]<now)
			num++;
		else
		{
			w[++cnt]=num;
			flag=1-flag;
			now=a[i];
		}
	}

	if(num)
		w[++cnt]=num;
	sort(w+1,w+1+cnt);
	dp[0]=1;
	for(int i=1;i<=cnt;i++)
		for(int j=n;j>=w[i];j--)
			dp[j]=dp[j-w[i]];
	if(dp[n])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return ;
}
signed main()
{
	int t;
	cin>>t;
	while(t--)
		solve();
	return 0;
}


#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
int cou[4005],beibao[4005];
int ans1=0;
int ans2=0;
int ans3=0;
void solve(){
	int n;
	ans1=ans2=ans3=0;
	sc(n);n*=2;
	int lef=1,minn,endd=0;
	sc(minn);ans1=ans2=ans3=0;
	for(int i=2;i<=n;i++){
		int u;ans1=ans2=ans3=0;
		sc(u);ans1=ans2=ans3=0;
		if(u>minn){
			cou[++endd]=i-lef;
			minn=u;lef=i;ans1=ans2=ans3=0;
		}
	}cou[++endd]=n+1-lef;
	for(int i=1;i<=n/2+1;i++){ans1=ans2=ans3=0;
		beibao[i]=0;
	}
	for(int i=1;i<=endd;i++){ans1=ans2=ans3=0;
		for(int j=n/2-cou[i];j>=0;j--){ans1=ans2=ans3=0;
			if(beibao[j]==1||j==0){
				beibao[j+cou[i]]=1;
				ans1=ans2=ans3=0;
			}
		}
	}if(beibao[n/2+ans1+ans2+ans3]==1){
		pf("YES\n");
	}else {
		pf("NO\n");
	}
}
int main(){
	int t;
	sc(t);
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 4040, M = 2020;

bitset<M> dp[N];
int a[N];

void solve(){
	int n;cin >> n;
	for(int i=0 ; i<2*n ; i++)
		cin >> a[i];
	a[2*n] = 1e9;
	vector<int> v;
	v.push_back(2*n);
	dp[2*n][0] = 1;
	for(int i=2*n-1 ; i>=0 ; i--){
		while(a[v.back()] < a[i])
			v.pop_back();
		int nxt = v.back();
		v.push_back(i);
		int cnt = nxt-i;
		dp[i] = (dp[nxt] << cnt) | dp[nxt];
	}
	if(dp[0][n])
		cout << "YES\n";
	else
		cout << "NO\n";
}

signed main(){
	int t;cin >> t;
	while(t --)
		solve();
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 4040, M = 2020;

bitset<M> dp[N];
int a[N];

void solve(){
	int n;cin >> n;
	for(int i=0 ; i<=2*n+100 ; i++){
		dp[i].reset();
		a[i] = -1e9;
	}
	for(int i=0 ; i<2*n ; i++)
		cin >> a[i];
	a[2*n] = 1e9;
	vector<int> v;
	v.push_back(2*n);
	dp[2*n][0] = 1;
	for(int i=2*n-1 ; i>=0 ; i--){
		while(a[v.back()] < a[i])
			v.pop_back();
		int nxt = v.back();
		v.push_back(i);
		int cnt = nxt-i;
		dp[i] = (dp[nxt] << cnt) | dp[nxt];
	}
	if(dp[0][n])
		cout << "YES\n";
	else
		cout << "NO\n";
}

signed main(){
	int t;cin >> t;
	while(t --)
		solve();
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 4400, M = 2200;

bitset<M> dp[N];
int a[N];

void solve(){
	int n;cin >> n;
	for(int i=0 ; i<=2*n+100 ; i++){
		dp[i].reset();
		a[i] = -1e9;
	}
	for(int i=0 ; i<2*n ; i++)
		cin >> a[i];
	a[2*n] = 1e9;
	vector<int> v;
	v.push_back(2*n);
	dp[2*n][0] = 1;
	for(int i=2*n-1 ; i>=0 ; i--){
		while(a[v.back()] < a[i])
			v.pop_back();
		int nxt = v.back();
		v.push_back(i);
		int cnt = nxt-i;
		dp[i] = (dp[nxt] << cnt) | dp[nxt];
	}
	if(dp[0][n])
		cout << "YES\n";
	else
		cout << "NO\n";
}

signed main(){
	int t;cin >> t;
	while(t --)
		solve();
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
  int n=N>>1;
  if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  //pair<int,int> x=make_pair(p,d);
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<V.size();++i){
    int diff=consume_forward?d-V[i]+V[p]:d+V[i]-V[p];
    if (diff>n||diff<-n)break;
    if (solve(V, Cache, i, diff, !consume_forward)){
      return Cache[p][n+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][n+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; scanf("%d",&m); N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; scanf("%d",&x);
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    int n=V.size();
    vector<vector<int>> Cache(n, vector<int>(N+1,-1));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    printf("%s\n",answer.c_str());
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

string NO="NO",YES="YES";

int main(){
  int n_cases; cin>>n_cases;
  while(n_cases--){
    int n; cin>>n;
    int N=n<<1;
    vector<int> V;
    int best=0,prev=-1;
    for (int i=0;i<N;++i){
      int x; cin>>x;
      if (x>best){
        if (prev>-1){
          V.push_back(i-prev);
        }
        prev=i;
        best=x;
      }
    }
    V.push_back(N-prev);
    int sum=accumulate(V.begin(),V.end(),0);
    if (sum%2!=0){
      cout<<NO<<endl;
    }else{
      int half_sum=sum>>1;
      bool ok[1+half_sum]; memset(ok,0,sizeof(ok));ok[0]=1;
      for (int i=0;i<V.size();++i){
        for (int j=half_sum-V[i];j>=0;--j){
          if(ok[j]) ok[j+V[i]]=1;
        }
      }
      cout<<(ok[half_sum]?YES:NO)<<endl;
    }
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

// can we make diff of "d" and position "p". Final result we're interested in
// has diff 0 at position 0.
//bool can_make(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, int multiplier){
bool can_make(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, int multiplier){
  int n=V.size();
  pair<int,int> x=make_pair(p,n+d);
  //if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  if (Cache.find(x)!=Cache.end()) return Cache[x];
  int highest_so_far=V[p];
  for (int i=1+p;i<n;++i){
    if (V[i]>highest_so_far && can_make(V, Cache, i, d-multiplier*(i-p), -multiplier)){
      //return Cache[p][n+d]=1;
      return Cache[x]=1;
    }
    if (highest_so_far < V[i]) highest_so_far=V[i];
  }
  //return Cache[p][n+d]=(multiplier*(n-p)==d);
  return Cache[x]=(multiplier*(n-p)==d);
}

void solve_case(){
  int m; cin>>m; int n=2*m;
  vector<int> V(n);
  for (int i=0;i<n;++i) cin>>V[i];
  //vector<vector<int>> Cache(n, vector<int>(2*n+1, -1));
  unordered_map<pair<int,int>, bool, HASH> Cache;
  string answer=can_make(V, Cache, 0, 0, 1)?"YES":"NO";
  cout<<answer<<endl;
}

int main(){
  int n_cases;
  cin>>n_cases;
  while(n_cases--){
    solve_case();
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
  //pair<int,int> x=make_pair(p,d);
  int n=V.size();
  if (Cache[p][N+d]!=-1) return Cache[p][N+d];
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<n;++i){
    if (solve(V, Cache, i, consume_forward?d-V[i]+V[p]:d+V[i]-V[p], !consume_forward)){
      return Cache[p][N+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][N+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; scanf("%d",&m); N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; scanf("%d",&x);
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    int n=V.size();
    vector<vector<int>> Cache(n, vector<int>(2*N+1,-1));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    printf("%s\n",answer.c_str());
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

// can we make diff of "d" and position "p". Final result we're interested in
// has diff 0 at position 0.
//bool can_make(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, int multiplier){
bool can_make(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, int multiplier){
  int n=V.size();
  pair<int,int> x=make_pair(p,n+d);
  //if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  if (Cache.find(x)!=Cache.end()) return Cache[x];
  int highest_so_far=V[p];
  for (int i=1+p;i<n;++i){
    if (V[i]>highest_so_far && can_make(V, Cache, i, d-multiplier*(i-p), -multiplier)){
      //return Cache[p][n+d]=1;
      return Cache[x]=1;
    }
    if (highest_so_far < V[i]) highest_so_far=V[i];
  }
  //return Cache[p][n+d]=(multiplier*(n-p)==d);
  return Cache[x]=(multiplier*(n-p)==d);
}

void solve_case(){
  int m; scanf("%d",&m); int n=m<<1;
  vector<int> V(n);
  for (int i=0;i<n;++i) scanf("%d", &V[i]);
  //vector<vector<int>> Cache(n, vector<int>(2*n+1, -1));
  unordered_map<pair<int,int>, bool, HASH> Cache;
  string answer=can_make(V, Cache, 0, 0, 1)?"YES":"NO";
  printf("%s\n",answer.c_str());
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    solve_case();
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

int Cache[1<<11][1<<11];

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
//bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, int p, int d, bool consume_forward){
  int n=N>>1;
  if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  //pair<int,int> x=make_pair(p,d);
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<V.size();++i){
    int diff=consume_forward?d-V[i]+V[p]:d+V[i]-V[p];
    if (diff>n||diff<-n)break;
    if (solve(V, i, diff, !consume_forward)){
      return Cache[p][n+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][n+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; scanf("%d",&m); N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; scanf("%d",&x);
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    memset(Cache,-1,sizeof(Cache));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    //string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    string answer=solve(V, 0, 0, true)?"YES":"NO";
    printf("%s\n",answer.c_str());
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
  //pair<int,int> x=make_pair(p,d);
  int n=V.size();
  if (Cache[p][N+d]!=-1) return Cache[p][N+d];
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<n;++i){
    if (solve(V, Cache, i, consume_forward?d-V[i]+V[p]:d+V[i]-V[p], !consume_forward)){
      return Cache[p][N+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][N+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; cin>>m; N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; cin>>x;
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    int n=V.size();
    vector<vector<int>> Cache(n, vector<int>(2*N+1,-1));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    cout<<answer<<endl;
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

// can we make diff of "d" and position "p". Final result we're interested in
// has diff 0 at position 0.
//bool can_make(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, int multiplier){
bool can_make(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
  pair<int,int> x=make_pair(p,d);
  //if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  if (Cache.find(x)!=Cache.end()) return Cache[x];
  int highest_so_far=V[p];
  for (int i=1+p;i<V.size();++i){
    if (V[i]>highest_so_far && can_make(V, Cache, i, consume_forward?d-i+p:d+i-p, !consume_forward)){
      //return Cache[p][n+d]=1;
      return Cache[x]=1;
    }
    if (highest_so_far < V[i]) highest_so_far=V[i];
  }
  //return Cache[p][n+d]=(multiplier*(n-p)==d);
  return Cache[x]=(consume_forward?V.size()-p:p-V.size())==d;
}

void solve_case(){
  int m; scanf("%d",&m); int n=m<<1;
  vector<int> V(n);
  for (int i=0;i<n;++i) scanf("%d", &V[i]);
  //vector<vector<int>> Cache(n, vector<int>(2*n+1, -1));
  unordered_map<pair<int,int>, bool, HASH> Cache;
  string answer=can_make(V, Cache, 0, 0, true)?"YES":"NO";
  printf("%s\n",answer.c_str());
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    solve_case();
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

int Cache[1<<12][1<<12];

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
//bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, int p, int d, bool consume_forward){
  int n=N>>1;
  if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  //pair<int,int> x=make_pair(p,d);
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<V.size();++i){
    int diff=consume_forward?d-V[i]+V[p]:d+V[i]-V[p];
    if (diff>n||diff<-n)break;
    if (solve(V, i, diff, !consume_forward)){
      return Cache[p][n+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][n+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; scanf("%d",&m); N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; scanf("%d",&x);
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    memset(Cache,-1,sizeof(Cache));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    //string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    string answer=solve(V, 0, 0, true)?"YES":"NO";
    printf("%s\n",answer.c_str());
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

//bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
  //pair<int,int> x=make_pair(p,d);
  if (Cache[p][V.size()+d]!=-1) return Cache[p][V.size()+d];
  //if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<V.size();++i){
    if (solve(V, Cache, i, consume_forward?d-V[i]+V[p]:d+V[i]-V[p], !consume_forward)){
      return Cache[p][V.size()+d]=1;
      //return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  //return Cache[x]=result;
  return Cache[p][V.size()+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; cin>>m; N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; cin>>x;
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }

    vector<vector<int>> Cache(V.size(), vector<int>(2*V.size()+1,-1));
    //unordered_map<pair<int,int>, bool, HASH> Cache;
    string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    cout<<answer<<endl;
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

int N;

bool solve(const vector<int>& V, unordered_map<pair<int,int>, bool, HASH>& Cache, int p, int d, bool consume_forward){
//bool solve(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, bool consume_forward){
  //if (Cache[p][N+d]!=-1) return Cache[p][N+d];
  pair<int,int> x=make_pair(p,d);
  if (Cache.find(x)!=Cache.end()) return Cache[x];
  for (int i=1+p;i<V.size();++i){
    int diff=consume_forward?d-V[i]+V[p]:d+V[i]-V[p];
    if (diff>N||diff<-N)break;
    if (solve(V, Cache, i, diff, !consume_forward)){
      //return Cache[p][N+d]=1;
      return Cache[x]=true;
    }
  }
  bool result=((consume_forward?N-V[p]:V[p]-N)==d);
  return Cache[x]=result;
  //return Cache[p][N+d]=result;
}

int main(){
  int n_cases; scanf("%d",&n_cases);
  while(n_cases--){
    int m; scanf("%d",&m); N=m<<1;
    vector<int> V;
    int best=0;
    for (int i=0;i<N;++i){
      int x; scanf("%d",&x);
      if (x>best){
        V.push_back(i);
        best=x;
      }
    }
    int n=V.size();
    //vector<vector<int>> Cache(n, vector<int>(2*N+1,-1));
    unordered_map<pair<int,int>, bool, HASH> Cache;
    string answer=solve(V, Cache, 0, 0, true)?"YES":"NO";
    printf("%s\n",answer.c_str());
  }
  return 0;
}


#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<ext/numeric>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;

typedef long long int i64;
typedef long long unsigned int u64;

#define ForEach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)

// can we make diff of "d" and position "p". Final result we're interested in
// has diff 0 at position 0.
bool can_make(const vector<int>& V, vector<vector<int>>& Cache, int p, int d, int multiplier){
  int n=V.size();
  if (Cache[p][n+d]!=-1) return Cache[p][n+d];
  int highest_so_far=V[p];
  for (int i=1+p;i<n;++i){
    if (V[i]>highest_so_far && can_make(V, Cache, i, d-multiplier*(i-p), -multiplier)){
      return Cache[p][n+d]=1;
    }
    if (highest_so_far < V[i]) highest_so_far=V[i];
  }
  return Cache[p][n+d]=(multiplier*(n-p)==d);
}

void solve_case(){
  int m; cin>>m; int n=2*m;
  vector<int> V(n);
  for (int i=0;i<n;++i) cin>>V[i];
  vector<vector<int>> Cache(n, vector<int>(2*n+1, -1));
  string answer=can_make(V, Cache, 0, 0, 1)?"YES":"NO";
  cout<<answer<<endl;
}

int main(){
  int n_cases;
  cin>>n_cases;
  while(n_cases--){
    solve_case();
  }
  return 0;
}