        #include<bits/stdc++.h>
        using namespace std;
        # define ll long long int

        int main(){
            #ifndef ONLINE_JUDGE
                freopen("input.txt","r",stdin);
                freopen("output.txt","w",stdout);
            #endif

            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t;
            cin>>t;
            while(t--){
                int n;
                cin>>n;
                int A[2*n];
                for(int i=0;i<2*n;i++){
                    cin>>A[i];
                }
                vector<int> a;
                // int max=2*n;
                // int gap;
                int cur=A[0];
                int len=1;
                for(int i=1;i<=2*n-1;i++){
                    if(A[i]< cur){
                        len++;
                    }
                    else{
                         // cout<<len<<endl;
                        a.push_back(len);
                        len=1;cur=A[i];
                    }
                }
                a.push_back(len);
                // for(int i=0;i<a.size();i++)
                //     cout<<a[i]<<" ";
                int dp[n+1][a.size()+1];

                for(int i=0;i<=n;i++){
                    dp[i][0]=0;
                }
                for(int i=0;i<=a.size();i++){
                    dp[0][i]=0;
                }

                for(int j=1;j<=n;j++){
                    for(int i=1;i<=a.size();i++){
                        if(j<a[i-1]){
                            dp[i][j]=dp[i-1][j];
                        }
                        else if(a[i-1]==j){
                            dp[i][j]=1;
                        }
                        else{
                            dp[i][j]=dp[i-1][j-a[i]];
                        }
                    }

                }

                if(dp[a.size()][n]==1){
                    cout<<"YES"<<endl;
                }
                else{
                    cout<<"NO"<<endl;
                }
            }

        }


        #include<bits/stdc++.h>
        using namespace std;
        # define ll long long int

        int main(){
            #ifndef ONLINE_JUDGE
                freopen("input.txt","r",stdin);
                freopen("output.txt","w",stdout);
            #endif

            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t;
            cin>>t;

            while(t--){

                // cout<<"check"<<endl;
                int n;
                cin>>n;
                int A[2*n];
                for(int i=0;i<2*n;i++){
                    cin>>A[i];
                }
                vector<int> a;

                // int max=2*n;
                // int gap;
                int cur=A[0];
                int len=1;
                for(int i=1;i<=2*n-1;i++){
                    if(A[i]< cur){
                        len++;
                    }
                    else{
                         // cout<<len<<endl;
                        a.push_back(len);
                        len=1;cur=A[i];
                    }
                }
                a.push_back(len);
                // for(int i=0;i<a.size();i++)
                //     cout<<a[i]<<" ";
                int dp[a.size()+1][n+1];

                for(int i=0;i<=n;i++){
                    dp[0][i]=0;
                }
                for(int i=0;i<=a.size();i++){
                    dp[i][0]=0;
                }

                for(int j=1;j<=n;j++){
                    for(int i=1;i<=a.size();i++){
                        if(j<a[i-1]){
                            dp[i][j]=dp[i-1][j];
                        }
                        else if(a[i-1]==j){
                            dp[i][j]=1;
                        }
                        else{
                            dp[i][j]=dp[i-1][j-a[i]];
                        }
                    }

                }

                if(dp[a.size()][n]==1){
                    cout<<"YES"<<endl;
                }
                else{
                    cout<<"NO"<<endl;
                }
                // cout<<t<<endl;
            }

        }


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define ll long long
#define ar array

int main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--){
    	int n; cin>>n;
    	int a[2*n];
    	for(int i=0;i<2*n;i++) cin>>a[i];
    	// cout<<n<<endl;
    	vector<int> sk;

    	int mx=a[0],cur=0;
    	for(int i=0;i<2*n;i++){
    		if(mx<a[i]){
    			mx=a[i];
    			sk.push_back(cur);
    			cur=1;
    		}else{
    			cur++;
    		}
    	}
    	sk.push_back(cur);
    	// for(int i=0;i<sk.size();i++)
    		// cout<<sk[i]<<" ";
    	// cout<<endl;

    int dp[(int)sk.size()+1][n+1];
    memset(dp,0,sizeof(dp));
    for(int j=1;j<=n;j++){
    	for(int i=1;i<=sk.size();i++){
    		dp[i][j]=dp[i-1][j];
    		if(j==sk[i-1]){
    			dp[i][j]=1;
    		}
    		if(sk[i-1]<j)
    			dp[i][j]=max(dp[i][j],dp[i-1][j-sk[i-1]]);

    	}
    }
    if(dp[sk.size()][n]){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }

    }
	return 0;

}


        #include<bits/stdc++.h>
        using namespace std;
        # define ll long long int

        int main(){
            //#ifndef ONLINE_JUDGE
                //freopen("input.txt","r",stdin);
                //freopen("output.txt","w",stdout);
            //#endif

            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t;
            cin>>t;

            while(t--){

                int n;
                cin>>n;

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

                int cur=A[0];
                int len=1;
                for(int i=1;i<=2*n-1;i++){
                    if(A[i]< cur){
                        len++;
                    }
                    else{
                        a.push_back(len);
                        len=1;cur=A[i];
                    }
                }
                a.push_back(len);
                //for(int i=0;i<(int)a.size();i++){
                //cout<<a[i]<<" ";}
                //cout<<endl;
                int dp[(int)a.size()+1][n+1];

                for(int i=0;i<=n;i++){
                    dp[0][i]=0;
                }
                for(int i=0;i<= (int)a.size();i++){
                    dp[i][0]=0;
                }
                // //cout<<a.size()<<endl;

                for(int j=1;j<=n;j++){
                    for(int i=1;i<= (int)a.size();i++){
                         if(j<a[i-1]){
                             dp[i][j]=dp[i-1][j];
                         }
                        else if(a[i-1]==j){
                            dp[i][j]=1;
                        }
                        else if(j>a[i-1]  ){
                             //if(j-a[i]>=0)
                                 dp[i][j]=max(dp[i-1][j-a[i-1]],dp[i-1][j]);
                        }
                     }

                }

                 if(dp[a.size()][n]==1){
                    cout<<"YES"<<endl;
                 }
                 else{
                     cout<<"NO"<<endl;
                 }
                // cout<<t<<endl;
            }

        }


#include<bits/stdc++.h>
using namespace std;
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n];
		for(int i=0;i<2*n;i++) cin>>s[i];
		vector<int> grps;
		int cnt=1,cur=s[0];
		s.push_back(2 * n + 1);
		for(int i=1;i<2*n+1;i++){
			if(s[i]<cur) cnt++;
			else{
				grps.push_back(cnt);
				cnt=1;
				cur=s[i];
			}
		}
		sort(grps.begin(),grps.end(),greater<int>());
		int sum=0;
		for(int i=0;i<grps.size();i++){
			if(sum+grps[i]<=n) sum+=grps[i];
		}
		if(sum==n) cout<<"YES\n";
		else cout<<"NO\n";
		/*int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		if(s2==0&&s1==0) cout<<"YES\n";
		else cout<<"NO\n";
		for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;
		if(flag&&){
			cout<<"NO\n";
			continue;
		}
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";*/
	}
}


#include<bits/stdc++.h>
using namespace std;
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n];
		for(int i=0;i<2*n;i++) cin>>s[i];
		vector<int> grps;
		int cnt=1,cur=s[0];
		for(int i=1;i<2*n;i++){
			if(s[i]<cur) cnt++;
			else{
				grps.push_back(cnt);
				cnt=1;
				cur=s[i];
			}
		}
		sort(grps.begin(),grps.end(),greater<int>());
		int sum=0;
		for(int i=0;i<grps.size();i++){
			if(sum+grps[i]<=n) sum+=grps[i];
		}
		if(sum==n) cout<<"YES\n";
		else cout<<"NO\n";
		/*int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		if(s2==0&&s1==0) cout<<"YES\n";
		else cout<<"NO\n";
		for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;
		if(flag&&){
			cout<<"NO\n";
			continue;
		}
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";*/
	}
}


#include<bits/stdc++.h>
using namespace std;
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n];
		for(int i=0;i<2*n;i++) cin>>s[i];
		int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		/*for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;*/
		/*if(flag&&){
			cout<<"NO\n";
			continue;
		}*/
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
bool sub_sum(vector<int> grps,int n){
	bool dp[2][n+1];
	dp[0][0]=true;
	for(int i=1;i<=n;i++) dp[0][i]=false;
	int flag=1;
	for(int i=1;i<=grps.size();i++){
		for(int j=1;j<=n;j++){
			dp[flag][j]=dp[flag^1][j];
			//cout<<grps[i-1]<<" ";
			if(j-grps[i-1]>=0) dp[flag][j]=dp[flag][j]||dp[flag^1][j-grps[i-1]];
			//cout<<j<<" "<<dp[flag][j]<<endl;
		}
		//for(int j=0;j<=n;j++) cout<<dp[flag][j]<<" ";
		//cout<<endl;
		flag=flag^1;
	}
	return dp[flag^1][n];
}
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n+1];
		for(int i=0;i<2*n;i++) cin>>s[i];
		vector<int> grps;
		int cnt=1,cur=s[0];
		//s[2*n]=(2 * n + 1);
		for(int i=1;i<2*n;i++){
			if(s[i]<cur) cnt++;
			else{
				grps.push_back(cnt);
				cnt=1;
				cur=s[i];
			}
		}
		grps.push_back(cnt);
		/*sort(grps.begin(),grps.end(),greater<int>());
		int sum=0;
		for(int i=0;i<grps.size();i++){
			if(sum+grps[i]<=n) sum+=grps[i];
		}*/
		//subset sum
		//for(int i=0;i<grps.size();i++) cout<<grps[i]<< " ";
		bool ans=sub_sum(grps,n);
		if(ans) cout<<"YES\n";
		else cout<<"NO\n";
		/*int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		if(s2==0&&s1==0) cout<<"YES\n";
		else cout<<"NO\n";
		for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;
		if(flag&&){
			cout<<"NO\n";
			continue;
		}
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";*/
	}
}


#include<bits/stdc++.h>
using namespace std;
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n+1];
		for(int i=0;i<2*n;i++) cin>>s[i];
		vector<int> grps;
		int cnt=1,cur=s[0];
		s[2*n]=(2 * n + 1);
		for(int i=1;i<2*n+1;i++){
			if(s[i]<cur) cnt++;
			else{
				grps.push_back(cnt);
				cnt=1;
				cur=s[i];
			}
		}
		sort(grps.begin(),grps.end(),greater<int>());
		int sum=0;
		for(int i=0;i<grps.size();i++){
			if(sum+grps[i]<=n) sum+=grps[i];
		}
		if(sum==n) cout<<"YES\n";
		else cout<<"NO\n";
		/*int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		if(s2==0&&s1==0) cout<<"YES\n";
		else cout<<"NO\n";
		for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;
		if(flag&&){
			cout<<"NO\n";
			continue;
		}
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";*/
	}
}


#include<bits/stdc++.h>
using namespace std;
main(){
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int s[2*n];
		for(int i=0;i<2*n;i++) cin>>s[i];
		int s1=n,s2=n;
		vector<int> v1,v2;
		int i=0,flag=0;
		while(s1>0||s2>0){
			int j=i+1;
			while(j<2*n&&s[i]>s[j]) j++;
			int sz=j-i;
			//cout<<s1<<" "<<s2<<" "<<sz<<endl;
			//cout<<sz<<endl;
			if(sz>s1&&sz>s2){
				flag=1;
				break;
			}
			else if(sz>s1){
				for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
			}
			else if(sz>s2){
				for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
			}
			else{
				if(s1<s2){
					for(int k=i;k<j;k++) v1.push_back(s[k]),s1--;
				}else{
					for(int k=i;k<j;k++) v2.push_back(s[k]),s2--;
				}
			}
			i=j;
		}
		if(s2==0&&s1==0) cout<<"YES\n";
		else cout<<"NO\n";
		/*for(int k=0;k<v1.size();k++) cout<<v1[k]<<" ";
		cout<<endl;
		for(int k=0;k<v2.size();k++) cout<<v2[k]<<" ";
		cout<<endl;
		cout<<i<<endl;
		if(flag&&){
			cout<<"NO\n";
			continue;
		}
		while(s1>0) v1.push_back(s[i]),i++,s1--;
		while(s2>0) v2.push_back(s[i]),i++,s2--;
		//merge
		vector<int> t;
		int k=0,j=0;
		for(int i=0;i<2*n;i++){
			if(j>=n) t.push_back(v2[k]),k++;
			else if(k>=n) t.push_back(v1[j]),j++;
			else if(v1[j]<v2[k]) t.push_back(v1[j]),j++;
			else t.push_back(v2[k]),k++;
		}
		flag=0;
		for(int i=0;i<2*n;i++){
			if(s[i]!=t[i]){
				flag=1;
				break;
			}
		}
		if(flag) cout<<"NO\n";
		else cout<<"YES\n";*/
	}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t{0};
    cin>>t;
    while(t--){
        int n{0};
        cin>>n;
        vector<int> vec(2*n);
        for(int i=0;i<2*n;i++){
            cin>>vec[i];
        }
        bool flag=false;
        if(vec[0]<vec[n]){
            flag=true;
        }else if(vec[0]<vec[1]){
            flag=true;
        }
        if(flag){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t{0};
    cin>>t;
    while(t--){
        int n{0};
        cin>>n;
        int y=-1;
        vector<int> vec;
        for(int i=0;i<2*n;i++){
            int x;
            cin>>x;
            if(x>y){
                y=x;
                vec.push_back(i);
            }
        }
        vector<int> sz;
        for(int i=0;i<vec.size();i++){
            if(i==vec.size()-1){
                sz.push_back(2*n-vec[i]);
            }else{
                sz.push_back(vec[i+1]-vec[i]);
            }
        }
        int k=sz.size();
        int dp[k+1][n+1];
        for(int i=0;i<n+1;i++){
            dp[0][i]=0;
        }
        for(int i=0;i<k+1;i++){
            dp[i][0]=1;
        }
        for(int i=1;i<k+1;i++){
            for(int j=1;j<n+1;j++){
                if(j-sz[i-1]>=0){
                    dp[i][j]=dp[i-1][j]|dp[i-1][j-sz[i-1]];
                }else{
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
        if(dp[k][n]==1){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;

const int N=4005;
const int inf=1000000000;

struct E{
	int to,w;
	E(){}
	E(int to,int w):to(to),w(w){}
};
struct node{
	int x,d,b;
	node(){}
	node(int x,int d,int b):x(x),d(d),b(b){}
};
int T,n,m,ans,mx,id;
int a[N];
bool dp[N][N][2];
vector<E> vec[N];
queue<node> q;

void solve(){
	int u,w;
	dp[1][0][0]=1;
	for (int i=1;i<=m;i++)
		for (int j=0;j<=n;j++)
			for (int b=0;b<=1;b++) if (dp[i][j][b])
				for (int k=0;k<vec[i].size();k++){
					u=vec[i][k].to;
					w=vec[i][k].w;
					if (i-j+w-1<=n) dp[u][i-j+w-1][b^1]|=dp[i][j][b];
				}
}

int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d",&n);
		for (int i=1;i<=n+n;i++) scanf("%d",&a[i]);
		m=n+n;
		for (int i=1;i<=m;i++){
			mx=a[i];
			for (int j=i+1;j<=m;j++){
				if (a[j]>mx&&j-i<=n){
					mx=a[j];
					id=j;
				}
			}
			vec[i].push_back(E(id,id-i));
			if (m-i+1<=n) vec[i].push_back(E(m+1,m-i+1));
		}
		solve();
		ans=dp[m+1][n][0]|dp[m+1][n][1];
		if (ans) printf("YES\n");
		else printf("NO\n");
		for (int i=1;i<=m;i++) vec[i].clear();
		for (int i=0;i<=m+1;i++)
			for (int j=0;j<=n;j++) dp[i][j][0]=dp[i][j][1]=0;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;

const int N=4005;
const int inf=1000000000;

struct E{
	int to,w;
	E(){}
	E(int to,int w):to(to),w(w){}
};
struct node{
	int x,d,b;
	node(){}
	node(int x,int d,int b):x(x),d(d),b(b){}
};
int T,n,m,ans,mx;
int a[N],pos[N];
bool dp[N][N][2];
vector<E> vec[N];
queue<node> q;

void solve(){
	int u,w;
	dp[1][0][0]=1;
	for (int i=1;i<=m;i++)
		for (int j=0;j<=n;j++)
			for (int b=0;b<=1;b++) if (dp[i][j][b])
				for (int k=0;k<vec[i].size();k++){
					u=vec[i][k].to;
					w=vec[i][k].w;
					if (i-j+w-1<=n) dp[u][i-j+w-1][b^1]|=dp[i][j][b];
				}
}

int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d",&n);
		for (int i=1;i<=n+n;i++) scanf("%d",&a[i]),pos[a[i]]=i;
		m=n+n;
		for (int i=1;i<=m;i++){
			mx=a[i];
			for (int j=i+1;j<=m;j++){
				if (a[j]>mx&&j-i<=n) vec[i].push_back(E(j,j-i));
				mx=max(mx,a[j]);
			}
			if (m-i+1<=n) vec[i].push_back(E(m+1,m-i+1));
		}
		solve();
		ans=dp[m+1][n][0]|dp[m+1][n][1];
		if (ans) printf("YES\n");
		else printf("NO\n");
		for (int i=1;i<=m;i++) vec[i].clear();
		for (int i=0;i<=m+1;i++)
			for (int j=0;j<=n;j++) dp[i][j][0]=dp[i][j][1]=0;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
using namespace std;

const int N=4005;
const int inf=1000000000;

int T,n,m,mx;
int a[N];
bool dp[N];
vector<int> lens,pos;

int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d",&n);
		m=n+n;
		dp[0]=1;
		mx=0;
		for (int i=1;i<=m;i++){
			scanf("%d",&a[i]);
			if (a[i]>mx){
				mx=a[i];
				pos.push_back(i);
			}
		}
		pos.push_back(m+1);
		sort(pos.begin(),pos.end());
		for (int i=1;i<pos.size();i++) lens.push_back(pos[i]-pos[i-1]);
		for (int i=0;i<lens.size();i++)
			for (int j=n;j>=lens[i];j--) dp[j]|=dp[j-lens[i]];
		if (dp[n]) printf("YES\n");
		else printf("NO\n");
		for (int i=1;i<=n;i++) dp[i]=0;
		pos.clear(); lens.clear();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<vector>
#include<queue>
using namespace std;

const int N=4005;
const int inf=1000000000;

struct E{
	int to,w;
	E(){}
	E(int to,int w):to(to),w(w){}
};
struct node{
	int x,d,b;
	node(){}
	node(int x,int d,int b):x(x),d(d),b(b){}
};
int T,n,m,ans,mx,id;
int a[N];
bool dp[N][N][2];
vector<E> vec[N];
queue<node> q;

void solve(){
	int u,w;
	dp[1][0][0]=1;
	for (int i=1;i<=m;i++)
		for (int j=0;j<=n;j++)
			for (int b=0;b<=1;b++) if (dp[i][j][b])
				for (int k=0;k<vec[i].size();k++){
					u=vec[i][k].to;
					w=vec[i][k].w;
					if (i-j+w-1<=n) dp[u][i-j+w-1][b^1]|=dp[i][j][b];
				}
}

int main(){
	scanf("%d",&T);
	while (T--){
		scanf("%d",&n);
		for (int i=1;i<=n+n;i++) scanf("%d",&a[i]);
		m=n+n;
		for (int i=1;i<=m;i++){
			mx=a[i]; id=0;
			for (int j=i+1;j<=m;j++){
				if (a[j]>mx&&j-i<=n){
					mx=a[j];
					id=j;
				}
			}
			if (id) vec[i].push_back(E(id,id-i));
			if (m-i+1<=n) vec[i].push_back(E(m+1,m-i+1));
		}
		solve();
		ans=dp[m+1][n][0]|dp[m+1][n][1];
		if (ans) printf("YES\n");
		else printf("NO\n");
		for (int i=1;i<=m;i++) vec[i].clear();
		for (int i=0;i<=m+1;i++)
			for (int j=0;j<=n;j++) dp[i][j][0]=dp[i][j][1]=0;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn=4002;
vector<int>g[mxn];
int n,m;
int a[mxn],pos[mxn];
bool ban[mxn];
vector<int>v;
int dp[mxn][mxn];
inline void solve(){
	cin>>n;for(int i=1;i<=n;++i)pos[i]=0;
	for(int i=1;i<=n;++i)ban[i]=0;
	v.clear();
	for(int i=1;i<=n*2;++i)cin>>a[i],pos[a[i]]=i;
	for(int i=n*2;i;--i){
		int cnt=0;
		for(int j=pos[i];j<=n*2 and !ban[j];)++cnt,ban[j]=1,++j;
		if(cnt)v.push_back(cnt);
	}
	for(int i=0;i<=v.size();++i)for(int j=0;j<=n;++j)dp[i][j]=0;
	dp[0][0]=1;
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();++i){
		for(int j=0;j<=n;++j){
			if(dp[i][j]==1){
				dp[i+1][j]=1;
				if(j+v[i]<=n){
					dp[i+1][j+v[i]]=1;
				}
			}
		}
	}
	if(dp[(int)(v.size())][n])cout<<"YES\n";
	else cout<<"NO\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;cin>>T;
	for(;T--;)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int mxn=4002;
vector<int>g[mxn];
int n,m;
int a[mxn],pos[mxn];
bool ban[mxn];
vector<int>v;
int dp[mxn][mxn];
inline void solve(){
	cin>>n;for(int i=1;i<=n*2;++i)pos[i]=0;
	for(int i=1;i<=n*2;++i)ban[i]=0;
	v.clear();
	for(int i=1;i<=n*2;++i)cin>>a[i],pos[a[i]]=i;
	for(int i=n*2;i;--i){
		int cnt=0;
		for(int j=pos[i];j<=n*2 and !ban[j];)++cnt,ban[j]=1,++j;
		if(cnt)v.push_back(cnt);
	}
	for(int i=0;i<=v.size();++i)for(int j=0;j<=n;++j)dp[i][j]=0;
	dp[0][0]=1;
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();++i){
		for(int j=0;j<=n;++j){
			if(dp[i][j]==1){
				dp[i+1][j]=1;
				if(j+v[i]<=n){
					dp[i+1][j+v[i]]=1;
				}
			}
		}
	}
	if(dp[(int)(v.size())][n])cout<<"YES\n";
	else cout<<"NO\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;cin>>T;
	for(;T--;)solve();
}


#include<bits/stdc++.h>
using namespace std;
const int mxn=4002;
vector<int>g[mxn];
int n,m;
int a[mxn],pos[mxn];
bool ban[mxn];
vector<int>v;
int dp[mxn][mxn];
inline void solve(){
	cin>>n;memset(pos,0,sizeof(pos));
	memset(ban,0,sizeof(ban));
	v.clear();
	for(int i=1;i<=n*2;++i)cin>>a[i],pos[a[i]]=i;
	for(int i=n*2;i;--i){
		int cnt=0;
		for(int j=pos[i];j<=n*2 and !ban[j];)++cnt,ban[j]=1,++j;
		if(cnt)v.push_back(cnt);
	}
//	cout<<"TT: ";for(int i:v)cout<<i<<' ';cerr<<'\n';
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();++i){
		for(int j=0;j<=n;++j){
			if(dp[i][j]==1){
				dp[i+1][j]=1;
				if(j+v[i]<=n){
					dp[i+1][j+v[i]]=1;
				}
			}
		}
	}
//	cout<<"DP: ";for(int i=0;i<=n;++i)cout<<dp[i]<<' ';cout<<'\n';
	if(dp[(int)(v.size())][n])cout<<"YES\n";
	else cout<<"NO\n";
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;cin>>T;
	for(;T--;)solve();
}


//time limit exceeded on test 7

#include <iostream>
#include <vector>

using namespace std;

bool add(vector<int> &include) {
    include[0]++;
    for (int i=0; i<include.size()-1; i++) {
        if (include[i] == 2) {
            include[i] = 0;
            include[i+1]++;
        }
        else {
            break;
        }
    }
    if (include[include.size()-1] == 2) {
        return true;
    }
    else {
        return false;
    }
}

int main() {
    int cases; cin >> cases;
    while (cases--) {
        int length; cin >> length;
        int biggest; cin >> biggest;
        int count = 1;
        int skip = 0; //-1 is yes, 1 is no
        vector<int> vals;
        for (int i=1; i<length*2; i++) {
            int num; cin >> num;
            if (num > biggest) {
                if (count > length) {
                    skip = 1;
                }
                else if (count == length) {
                    skip = -1;
                }
                vals.push_back(count);
                count = 1;
                biggest = num;
            }
            else {
                count++;
            }
        }
        vals.push_back(count);
        if (count > length) {
            skip = 1;
        }
        else if (count == length) {
            skip = -1;
        }

        if (skip == 0) {
            vector<int> include(vals.size(), 0);
            bool stop = add(include);
            bool done = false;
            // for (int i=0; i<vals.size(); i++) {
            //     cout << vals[i] << " ";
            // }
            // cout << "\n";
            while (!stop) {
                int sum = 0;
                for (int i=0; i<include.size(); i++) {
                    if (include[i] == 1) {
                        sum += vals[i];
                    }
                }
                if (sum == length) {
                    done = true;
                    break;
                }
                stop = add(include);
            }

            if (done) {
                cout << "YES\n";
            }
            else {
                cout << "NO\n";
            }
        }
        else if (skip == -1) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
}


#include <iostream>
#include <vector>

using namespace std;

bool add(vector<int> &include) {
    include[0]++;
    for (int i=0; i<include.size()-1; i++) {
        if (include[i] == 2) {
            include[i] = 0;
            include[i+1]++;
        }
        else {
            break;
        }
    }
    if (include[include.size()-1] == 2) {
        return true;
    }
    else {
        return false;
    }
}

int main() {
    int cases; cin >> cases;
    while (cases--) {
        int length; cin >> length;
        int biggest; cin >> biggest;
        int count = 1;
        vector<int> vals;
        for (int i=1; i<length*2; i++) {
            int num; cin >> num;
            if (num > biggest) {
                vals.push_back(count);
                count = 1;
                biggest = num;
            }
            else {
                count++;
            }
        }
        vals.push_back(count);

        vector<int> include(vals.size(), 0);
        bool stop = add(include);
        bool done = false;
        // for (int i=0; i<vals.size(); i++) {
        //     cout << vals[i] << " ";
        // }
        // cout << "\n";
        while (!stop) {
            int sum = 0;
            for (int i=0; i<include.size(); i++) {
                if (include[i] == 1) {
                    sum += vals[i];
                }
            }
            if (sum == length) {
                done = true;
                break;
            }
            stop = add(include);
        }

        if (done) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
}


#include <iostream>
#include <vector>

using namespace std;

int main() {
    int cases; cin >> cases;
    while (cases--) {
        int length; cin >> length;
        int biggest; cin >> biggest;
        int count = 1;
        int skip = 0; //-1 is yes, 1 is no
        vector<int> vals;
        for (int i=1; i<length*2; i++) {
            int num; cin >> num;
            if (num > biggest) {
                if (count > length) {
                    skip = 1;
                }
                else if (count == length) {
                    skip = -1;
                }
                vals.push_back(count);
                count = 1;
                biggest = num;
            }
            else {
                count++;
            }
        }
        vals.push_back(count);
        if (count > length) {
            skip = 1;
        }
        else if (count == length) {
            skip = -1;
        }

        if (skip == 0) {
            vector<bool> sums(length*2, false);
            sums[0] = true;
            for (int i=0; i<vals.size(); i++) {
                for (int j=length*2-1; j>=0; j--) {
                    if (sums[j]) {
                        sums[j+vals[i]] = true;
                    }
                }
            }

            if (sums[length]) {
                cout << "YES\n";
            }
            else {
                cout << "NO\n";
            }
        }
        else if (skip == -1) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
    }
}


#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef tuple<int,int,int> iii;
typedef vector<ll> vll;
typedef map<int, int> mii;

int n;
int a[4002];
vi b,c;
bool f(int x){
	if(x==-1) return true;

	bool ans = false;
	if(b.size() < n && (c.empty() || a[x] < c[c.size()-1])){
		b.push_back(a[x]);
		if(f(x-1)) return true;
		b.pop_back();
	}

	if(c.size() < n && (b.empty() || a[x] < b[b.size()-1])){
		c.push_back(a[x]);
		if(f(x-1)) return true;
		c.pop_back();
	}
	return false;
}

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

    int tc; cin>>tc;
    while(tc--){
    	cin>>n;
    	b.clear(); c.clear();
    	for(int i=0; i<2*n; i++){
    		cin>>a[i];
		}
		if(f(2*n-1)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef tuple<int,int,int> iii;
typedef vector<ll> vll;
typedef map<int, int> mii;

int n;
vi leng;
vector<vi> visited;

bool dp(int u, int sum){
	if(sum>n || u==-1) return false;
	if(visited[u][sum]) return false;
	visited[u][sum] = true;
	if(leng[u] + sum == n) return true;
	return (dp(u-1, sum) || dp(u-1, sum+leng[u]));
}

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

    int tc; cin>>tc;
    while(tc--){
    	cin>>n;
    	vi a(2*n);
    	leng.clear();
    	cin>>a[0];
    	int high = a[0], prev = 0;
    	for(int i=1; i<2*n; i++){
    		cin>>a[i];
    		if(a[i] > high){
    			leng.push_back(i-prev);
    			prev = i;
    			high = a[i];
			}
		}
		leng.push_back(2*n - prev);
    	visited.assign(leng.size(), vi(n+2, false));
		if(dp(leng.size()-1, 0)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef tuple<int,int,int> iii;
typedef vector<ll> vll;
typedef map<int, int> mii;

int n;
vi leng;
bool dp(int u, int sum){
	if(sum>n || u==-1) return false;
	if(leng[u] + sum == n) return true;
	return (dp(u-1, sum) || dp(u-1, sum+leng[u]));
}

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

    int tc; cin>>tc;
    while(tc--){
    	cin>>n;
    	vi a(2*n);
    	leng.clear();
    	cin>>a[0];
    	int high = a[0], prev = 0;
    	for(int i=1; i<2*n; i++){
    		cin>>a[i];
    		if(a[i] > high){
    			leng.push_back(i-prev);
    			prev = i;
    			high = a[i];
			}
		}
		leng.push_back(2*n - prev);
		if(dp(leng.size()-1, 0)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

    return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef tuple<int,int,int> iii;
typedef vector<ll> vll;
typedef map<int, int> mii;

int n;
vi leng;
bool dp(int u, int sum){
	if(sum>n || u==-1) return false;
	if(leng[u] + sum == n) return true;
	return (dp(u-1, sum) || dp(u-1, sum+leng[u]));
}

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

    int tc; cin>>tc;
    while(tc--){
    	cin>>n;
    	vi a(2*n);
    	leng.clear();
    	cin>>a[0];
    	int high = a[0], prev = 0;
    	for(int i=1; i<2*n; i++){
    		cin>>a[i];
    		if(a[i] > high){
    			leng.push_back(i-prev);
    			prev = i;
    			high = a[i];
			}
		}
		leng.push_back(2*n - prev);
		for(auto x:leng) cout<<x<<" ";
		cout<<endl;
		if(dp(leng.size()-1, 0)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int TT;
void solve(int t);
void answer() {
    cin>>TT;
    REP1(t,TT) solve(t);
}
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    answer();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 4222
#else
#define SIZE 4222
#endif

int N,Q,K;
int P[SIZE];
int DP[SIZE];

void solve(int _t) {
    cin>>N;
    REP(i,2*N)cin>>P[i];
    vector<int> V;
    int n = 2*N;
    int prev = 2*N;
    vector<int> C(2*N+1,0);
    RREP(i,2*N) {
        C[P[i]] = 1;
        if (P[i] == n) {
            V.push_back(prev-i);
            while(C[n]) n--;
            prev = i;
        }
    }
    REP(i,SIZE)DP[i]=0;
    DP[0]=1;
    DP[V[0]]=1;
    REP(i,V.size()-1) {
        RREP(j,SIZE) if(DP[j]) {
            int n = j+V[i+1];
            if (n>2*N) break;
            DP[n] = 1;
        }
    }
    cout << (DP[N] ? "YES" : "NO") << endl;
}


#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int TT;
void solve(int t);
void answer() {
    cin>>TT;
    REP1(t,TT) solve(t);
}
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    answer();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,Q,K;
int P[SIZE];

bool check(int n) {
    vector<int> A, B;
    REP(i,2*N) {
        if (n <= i && B.size() < N) {
            B.push_back(P[i]);
        } else {
            A.push_back(P[i]);
        }
    }
    reverse(ALL(A));
    reverse(ALL(B));
    REP(i,2*N) {
        int v;
        if (B.empty() || A.back() < B.back()) {
            v = A.back();
            A.pop_back();
        } else {
            v = B.back();
            B.pop_back();
        }
        if (v != P[i]) return false;
    }
    return true;
}

void solve(int _t) {
    cin>>N;
    REP(i,2*N)cin>>P[i];
    REP1(i,N) {
        if (check(i)) {
            cout << "YES" << endl;
            return;
        }
    }
    cout << "NO" << endl;
}


#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

int TT;
void solve(int t);
void answer() {
    cin>>TT;
    REP1(t,TT) solve(t);
}
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    answer();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 20
#else
#define SIZE 4222
#endif

int N,Q,K;
int P[SIZE];
int DP[SIZE];

void solve(int _t) {
    cin>>N;
    REP(i,2*N)cin>>P[i];
    vector<int> V;
    int n = 2*N;
    int prev = 2*N;
    vector<int> C(2*N+1,0);
    RREP(i,2*N) {
        C[P[i]] = 1;
        if (P[i] == n) {
            V.push_back(prev-i);
            while(C[n]) n--;
            prev = i;
        }
    }
    REP(i,SIZE)DP[i]=0;
    DP[0]=1;
    DP[V[0]]=1;
    REP(i,V.size()) {
        RREP(j,SIZE) if(DP[j]) {
            int n = j+V[i+1];
            if (n>=2*N) continue;
            DP[n] = 1;
        }
    }
    cout << (DP[N] ? "YES" : "NO") << endl;
}


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

#define cs const
#define mp make_pair
#define int long long
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i = x; i <= y; ++ i)
#define sep(i, x, y) for(int i = x; i >= y; -- i)
#define fore(i, x) (int i = fir[x]; i; i = nex[i])

cs int ff = 4e5 + 15;
cs int M = 998244353;
cs int inf = 1e18 + 1;

int n, a[ff];
int b[ff], top, f[4333][4333];
void init()
{
	cin >> n; top = 0;
	rep(i, 1, n + n) scanf("%lld", &a[i]);
	int now = 1, s = 1;
	rep(i, 2, n + n)
	{
		if(a[now] > a[i]) s ++;
		else b[++top] = s, s = 1, now = i;
	}
	b[++top] = s;
	f[0][0] = 1;
	rep(i, 1, top)
	{
		rep(j, 0, n + n) f[i][j] += f[i - 1][j];
		rep(j, b[i], n + n)
			f[i][j] += f[i - 1][j - b[i]];
	}
	if(f[top][n]) cout << "YES\n";
	else cout << "NO\n";
	rep(i, 1, top) rep(j, 0, n + n) f[i][j] = 0;
}

signed main()
{
	int Ts = 1;
	cin >> Ts;
	rep(i, 1, Ts)
		init();
}
/*
5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1
*/


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

#define cs const
#define mp make_pair
#define int long long
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i = x; i <= y; ++ i)
#define sep(i, x, y) for(int i = x; i >= y; -- i)
#define fore(i, x) (int i = fir[x]; i; i = nex[i])

cs int ff = 4e5 + 15;
cs int M = 998244353;
cs int inf = 1e18 + 1;

int n, a[ff];
int b[ff], top, f[2333][2333];
void init()
{
	cin >> n; top = 0;
	rep(i, 1, n + n) scanf("%lld", &a[i]);
	int now = 1, s = 1;
	rep(i, 2, n + n)
	{
		if(a[now] > a[i]) s ++;
		else b[++top] = s, s = 1, now = i;
	}
	b[++top] = s;
	f[0][0] = 1;
	rep(i, 1, top)
	{
		rep(j, 0, n + n) f[i][j] += f[i - 1][j];
		rep(j, b[i], n + n)
			f[i][j] += f[i - 1][j - b[i]];
	}
	if(f[top][n]) cout << "YES\n";
	else cout << "NO\n";
	rep(i, 1, top) rep(j, 0, n + n) f[i][j] = 0;
}

signed main()
{
	int Ts = 1;
	cin >> Ts;
	rep(i, 1, Ts)
		init();
}
/*
5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1
*/


///apigs property
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,a[555555],dp[5555][5555],k,l,m,n,o,p;
map<ll,ll>mp;
vector<ll>v,adj[555555];
const ll mod=1e9+7;
bool mem(ll id,ll sum){
    if(id==m){
        if(sum==n)return 1;
        else return 0;
    }
    ll &r=dp[id][sum];
    if(r!=-1)return r;
    return mem(id+1,sum+v[id])|mem(id+1,sum);
}
int main(){
    cin>>q;
    while(q--){
        v.clear();
        cin>>n;
        n*=2;
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                dp[i][j]=-1;
            }
        }
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        for(ll i=0;i<n;i++){
            o=a[i];
            p=1;
            while(a[i+1]<o&&i+1<n)i++,p++;
            v.push_back(p);
        }
        m=v.size();
        n/=2;
        if(mem(0,0))cout<<"YES\n";
        else cout<<"NO\n";
    }
}


///apigs property
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,a[555555],dp[5555][5555],k,l,m,n,o,p;
map<ll,ll>mp;
vector<ll>v,adj[555555];
const ll mod=1e9+7;
bool mem(ll id,ll sum){
    if(id==m){
        if(sum==n)return 1;
        else return 0;
    }
    ll &r=dp[id][sum];
    if(r!=-1)return r;
    return mem(id+1,sum+v[id])|mem(id+1,sum);
}
int main(){
    cin>>q;
    while(q--){
        v.clear();
        cin>>n;
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                dp[i][j]=-1;
            }
        }
        n*=2;
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        for(ll i=0;i<n;i++){
            o=a[i];
            p=1;
            while(a[i+1]<o&&i+1<n)i++,p++;
            v.push_back(p);
        }
        m=v.size();
        n/=2;
        if(mem(0,0))cout<<"YES\n";
        else cout<<"NO\n";
    }
}


///apigs property
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,a[555555],dp[5555][5555],k,l,m,n,o,p;
map<ll,ll>mp;
vector<ll>v,adj[555555];
const ll mod=1e9+7;
string s,t;
bool mem(ll id,ll sum){
    if(id==m){
        if(sum==n)return 1;
        else return 0;
    }
    ll &r=dp[id][sum];
    if(r!=-1)return r;
    return r=mem(id+1,sum+v[id])|mem(id+1,sum);
}
int main(){
    cin>>q;
    while(q--){
        v.clear();
        cin>>n;
        n*=2;
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                dp[i][j]=-1;
            }
        }
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        for(ll i=0;i<n;i++){
            o=a[i];
            p=1;
            while(a[i+1]<o&&i+1<n)i++,p++;
            v.push_back(p);
        }
        m=v.size();
        n/=2;
        if(mem(0,0))cout<<"YES\n";
        else cout<<"NO\n";
    }
}


///apigs property
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll q,a[55555],dp[1005][1005],k,l,m,n,o,p;
map<ll,ll>mp;
vector<ll>v,adj[555555];
const ll mod=1e9+7;
string s,t;
bool mem(ll id,ll sum){
    if(id==m){
        if(sum==n)return 1;
        else return 0;
    }
    ll &r=dp[id][sum];
    if(r!=-1)return r;
    return mem(id+1,sum+v[id])|mem(id+1,sum);
}
int main(){
    cin>>q;
    while(q--){
        v.clear();
        cin>>n;
        n*=2;
        for(ll i=0;i<n;i++){
            for(ll j=0;j<n;j++){
                dp[i][j]=-1;
            }
        }
        for(ll i=0;i<n;i++){
            cin>>a[i];
        }
        for(ll i=0;i<n;i++){
            o=a[i];
            p=1;
            while(a[i+1]<o&&i+1<n)i++,p++;
            v.push_back(p);
        }
        m=v.size();
        n/=2;
        if(mem(0,0))cout<<"YES\n";
        else cout<<"NO\n";
    }
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef long long ll;

int t;
int n;
char s1[100000 + 10];
char s2[100000 + 10];
vector <int> ans;

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        ans.clear();
        scanf("%d", &n);
        scanf("%s", s1);
        scanf("%s", s2);
        int front = 0;
        int time = 0;
        for(int i = n - 1;i >= 1; i--)
        {
            time = n - i - 1;
            if((n - i - 1) & 1) front = n - ((time + 1) / 2);
            else front = time / 2;
            int t = (s1[front] - '0') ^ (time % 2);
            if(t == s2[i] - '0')
            {
                ans.push_back(1);
            }
            ans.push_back(i + 1);
        }
        time = n - 1;
        if(time & 1) front = n - (n / 2);
        else front = time / 2;
        int t = (s1[front] - '0') ^ (time % 2);
        if(t != s2[0] - '0') ans.push_back(1);
        printf("%d", ans.size());
        for(int i = 0;i < ans.size(); i++)
        {
            printf(" %d", ans[i]);
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef long long ll;

int t;
int n;
int a[4000 + 10];
int dp[4000 + 10];
vector<int>len;

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        int num = 0;
        int maxn = 0;
        int maxi = 0;
        //a[0] = 0x3f3f3f3f;
        len.clear();
        for(int i = 1;i <= 2 * n; i++)
        {
            scanf("%d", &a[i]);
            if(i == 1){
                maxn = a[i];
                maxi = i;
                continue;
            }
            if(maxn < a[i])
            {
                maxn = a[i];
                len.push_back(i - maxi);
                maxi = i;
            }
        }
        len.push_back(2 * n + 1 - maxi);
        memset(dp, 0, sizeof(dp));
        for(int i = 0;i < len.size(); i++)
        {
            //printf("%d ", len[i]);
            for(int j = n - len[i];j >= 0; j--)
            {
                dp[j + len[i]] = max(dp[j + len[i]], dp[j] + len[i]);
            }
        }
        if(dp[n] == n) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef long long ll;

int t;
int n;
int a[4000 + 10];
int dp[4000 + 10];
vector<int>len;

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        int num = 0;
        int maxn = 0;
        int maxi = 0;
        //a[0] = 0x3f3f3f3f;
        len.clear();
        for(int i = 1;i <= 2 * n; i++)
        {
            scanf("%d", &a[i]);
            if(i == 1){
                maxn = a[i];
                maxi = i;
                continue;
            }
            if(maxn < a[i])
            {
                maxn = a[i];
                len.push_back(i - maxi);
                maxi = i;
            }
        }
        len.push_back(2 * n + 1 - maxi);
        memset(dp, 0, sizeof(dp));
        for(int i = 0;i < len.size(); i++)
        {
            printf("%d ", len[i]);
            for(int j = n - len[i];j >= 0; j--)
            {
                dp[j + len[i]] = max(dp[j + len[i]], dp[j] + len[i]);
            }
        }
        if(dp[n] == n) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void R (int &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
inline void R (long long &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
long long ans;
int mod;
inline int ksm(int n, int k) {
    int ans = 1;
    while(k) {
        if(k & 1) ans = (long long) ans * n % mod;
        n = (long long) n * n % mod;
        k>>=1;
    }
    return ans;
}
void extgcd(long long a,long long b,long long& d,long long& x,long long& y){
    if(!b){ d=a; x=1; y=0;}
    else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
long long inv(long long a,long long n){
    long long d,x,y;
    extgcd(a,n,d,x,y);
    return d==1?(x+n)%n:-1;
}
string s;
int T;
char a1[100005], b[100005];
int tree[600010][3],delta[600010];
int m,a[150010],num[150010];
const int Q=100005;
int si[Q],ls[Q],rs[Q],f[Q],v[Q],maxn[Q],sum[Q],root=1,n,ch[Q]={0};
void lx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    rs[y]=ls[x];
    f[rs[y]]=y;
    f[x]=z;
    f[y]=x;
    ls[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void rx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    ls[y]=rs[x];
    f[ls[y]]=y;
    f[x]=z;
    f[y]=x;
    rs[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void pd(int x)
{
    swap(ls[x],rs[x]);
    if(ls[x])ch[ls[x]]^=1;
    if(rs[x])ch[rs[x]]^=1;
    ch[x]=0;
}
void splay(int x,int goal)
{

    while(f[x]!=goal&&f[x]!=0)
    {
        if(ch[x])pd(x);
        int y=f[x],z=f[y];
        if(z!=0&&z!=goal)
        {
            if(ch[z])pd(z);
            if(ch[y])pd(y);
            if(ls[z]==y)
                if(ls[y]==x)rx(y),rx(x);
                else lx(x),rx(x);
            else if(rs[y]==x)lx(y),lx(x);
                else rx(x),lx(x);
        }
        else
        {
            if(ch[y])pd(y);
            if(ls[y]==x)rx(x);
            else lx(x);
        }
    }
    if(f[x]==0)root=x;
}
int gk(int k)
{
    if(k==0)return 0;
    si[0]=0;
    int p=root;
    while(p)
    {
        if(ch[p])pd(p);
        if(si[ls[p]]+1==k)break;
        if(si[ls[p]]<k)k-=si[ls[p]]+1,p=rs[p];
        else p=ls[p];
    }
    return p;
}
vector <int> ans1;
int dp[4005][2][2];
int main() {
    R(T);
    int n, m;
    int a[100005];
    while(T-- ){
      R(n);
      int tn = n * 2;

      for(int i = 1;i <= tn; ++i) {
        R(a[i]);
        dp[i][0][0] = dp[i][1][0] = 0;
        dp[i][0][1] = dp[i][1][1] = 0;
      }
      int last = 0, lastnum = 0;
      int tot = 0 ;
      bool pd = 0;
      bool opt = 0;
      dp[0][0][0] = dp[0][1][0] = 1;
      for(int i = 1; i <= tn; ++i) {
          if(a[i] > lastnum) {
              lastnum = a[i];
              tot = i - last;
              for(int j = i; j >= tot; --j) {
                  dp[j][0][opt ^ 1] |= dp[j - tot][0][opt];
                  dp[j][1][opt ^ 1] |= dp[j - tot + 1][0][opt];
                  dp[j][0][opt ^ 1] |= dp[j - 1][1][opt];
              }
              for(int j = 0; j <= tn; ++j) {
                  dp[j][0][opt] = dp[j][1][opt] = 0;
              }
              opt ^= 1;
            /*  printf("i = %d\n", i);
              for(int m = 1; m <= n; ++m) {
                printf("dp[%d][%d][%d] = %d\n", m, 0,opt, dp[m][0][opt]);
                printf("dp[%d][%d][%d] = %d\n", m, 1, opt,dp[m][1][opt]);
             }*/
              last = i;
          }
      }
      tot = tn - last;
      if(dp[n - tot][0][opt] || dp[n - tot][1][opt]) pd = 1;
     /* for(int i = 1; i <= n; ++i) {
          printf("dp[%d][%d][%d] = %d\n", i, 0,opt, dp[i][0][opt]);
          printf("dp[%d][%d][%d] = %d\n", i, 1, opt,dp[i][1][opt]);
      }*/
      if(pd) {
          puts("YES");
      } else {
          puts("NO");
      }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void R (int &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
inline void R (long long &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
long long ans;
int mod;
inline int ksm(int n, int k) {
    int ans = 1;
    while(k) {
        if(k & 1) ans = (long long) ans * n % mod;
        n = (long long) n * n % mod;
        k>>=1;
    }
    return ans;
}
void extgcd(long long a,long long b,long long& d,long long& x,long long& y){
    if(!b){ d=a; x=1; y=0;}
    else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
long long inv(long long a,long long n){
    long long d,x,y;
    extgcd(a,n,d,x,y);
    return d==1?(x+n)%n:-1;
}
string s;
int T;
char a1[100005], b[100005];
int tree[600010][3],delta[600010];
int m,a[150010],num[150010];
const int Q=100005;
int si[Q],ls[Q],rs[Q],f[Q],v[Q],maxn[Q],sum[Q],root=1,n,ch[Q]={0};
void lx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    rs[y]=ls[x];
    f[rs[y]]=y;
    f[x]=z;
    f[y]=x;
    ls[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void rx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    ls[y]=rs[x];
    f[ls[y]]=y;
    f[x]=z;
    f[y]=x;
    rs[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void pd(int x)
{
    swap(ls[x],rs[x]);
    if(ls[x])ch[ls[x]]^=1;
    if(rs[x])ch[rs[x]]^=1;
    ch[x]=0;
}
void splay(int x,int goal)
{

    while(f[x]!=goal&&f[x]!=0)
    {
        if(ch[x])pd(x);
        int y=f[x],z=f[y];
        if(z!=0&&z!=goal)
        {
            if(ch[z])pd(z);
            if(ch[y])pd(y);
            if(ls[z]==y)
                if(ls[y]==x)rx(y),rx(x);
                else lx(x),rx(x);
            else if(rs[y]==x)lx(y),lx(x);
                else rx(x),lx(x);
        }
        else
        {
            if(ch[y])pd(y);
            if(ls[y]==x)rx(x);
            else lx(x);
        }
    }
    if(f[x]==0)root=x;
}
int gk(int k)
{
    if(k==0)return 0;
    si[0]=0;
    int p=root;
    while(p)
    {
        if(ch[p])pd(p);
        if(si[ls[p]]+1==k)break;
        if(si[ls[p]]<k)k-=si[ls[p]]+1,p=rs[p];
        else p=ls[p];
    }
    return p;
}
vector <int> ans1;
int dp[4005][2][2];
int main() {
    R(T);
    int n, m;
    int a[100005];
    while(T-- ){
      R(n);
      int tn = n * 2;

      for(int i = 1;i <= tn; ++i) {
        R(a[i]);
        dp[i][0][0] = dp[i][1][0] = 0;
        dp[i][0][1] = dp[i][1][1] = 0;
      }
      int last = 0, lastnum = 0;
      int tot = 0 ;
      bool pd = 0;
      bool opt = 0;
      dp[0][0][0] = dp[0][1][0] = 1;
      for(int i = 1; i <= tn; ++i) {
          if(a[i] > lastnum) {
              lastnum = a[i];
              tot = i - last;
              for(int j = i; j >= 0; --j) {
              	if(j >= tot)
                  dp[j][0][opt ^ 1] |= dp[j - tot][0][opt];
                if(j >= tot - 1)
                  dp[j][1][opt ^ 1] |= dp[j - tot + 1][0][opt];
                  dp[j][1][opt ^ 1] |= dp[j][1][opt];
                if(j >= 1)
                  dp[j][0][opt ^ 1] |= dp[j - 1][1][opt];
              }
              for(int j = 0; j <= tn; ++j) {
                  dp[j][0][opt] = dp[j][1][opt] = 0;
              }
              opt ^= 1;
            /*  printf("i = %d\n", i);
              for(int m = 1; m <= n; ++m) {
                printf("dp[%d][%d][%d] = %d\n", m, 0,opt, dp[m][0][opt]);
                printf("dp[%d][%d][%d] = %d\n", m, 1, opt,dp[m][1][opt]);
             }*/
              last = i;
          }
      }
      tot = tn - last;
      if(dp[n - tot][0][opt] || dp[n][1][opt]) pd = 1;
     /* for(int i = 1; i <= n; ++i) {
          printf("dp[%d][%d][%d] = %d\n", i, 0,opt, dp[i][0][opt]);
          printf("dp[%d][%d][%d] = %d\n", i, 1, opt,dp[i][1][opt]);
      }*/
      if(pd) {
          puts("YES");
      } else {
          puts("NO");
      }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
inline void R (int &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
inline void R (long long &v) {
    static char ch;
    v = 0;
    bool p = 0;
    do {
        ch = getchar();
        if (ch == '-') p = 1;
    } while (!isdigit(ch));
    while (isdigit(ch)) {
        v = (v + (v << 2) << 1) + (ch ^ '0');
        ch = getchar();
    }
    if (p) v = -v;
}
long long ans;
int mod;
inline int ksm(int n, int k) {
    int ans = 1;
    while(k) {
        if(k & 1) ans = (long long) ans * n % mod;
        n = (long long) n * n % mod;
        k>>=1;
    }
    return ans;
}
void extgcd(long long a,long long b,long long& d,long long& x,long long& y){
    if(!b){ d=a; x=1; y=0;}
    else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
long long inv(long long a,long long n){
    long long d,x,y;
    extgcd(a,n,d,x,y);
    return d==1?(x+n)%n:-1;
}
string s;
int T;
char a1[100005], b[100005];
int tree[600010][3],delta[600010];
int m,a[150010],num[150010];
const int Q=100005;
int si[Q],ls[Q],rs[Q],f[Q],v[Q],maxn[Q],sum[Q],root=1,n,ch[Q]={0};
void lx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    rs[y]=ls[x];
    f[rs[y]]=y;
    f[x]=z;
    f[y]=x;
    ls[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void rx(int x)
{
    int y=f[x],z=f[y];
    if(z)if(ls[z]==y)ls[z]=x;
        else rs[z]=x;
    ls[y]=rs[x];
    f[ls[y]]=y;
    f[x]=z;
    f[y]=x;
    rs[x]=y;
    si[x]=si[y];
    si[y]=si[ls[y]]+si[rs[y]]+1;
    maxn[x]=maxn[y];
    maxn[y]=max(max(maxn[ls[y]],maxn[rs[y]]),v[y]);
    sum[x]=sum[y];
    sum[y]=sum[ls[y]]+sum[rs[y]]+v[y];
}
void pd(int x)
{
    swap(ls[x],rs[x]);
    if(ls[x])ch[ls[x]]^=1;
    if(rs[x])ch[rs[x]]^=1;
    ch[x]=0;
}
void splay(int x,int goal)
{

    while(f[x]!=goal&&f[x]!=0)
    {
        if(ch[x])pd(x);
        int y=f[x],z=f[y];
        if(z!=0&&z!=goal)
        {
            if(ch[z])pd(z);
            if(ch[y])pd(y);
            if(ls[z]==y)
                if(ls[y]==x)rx(y),rx(x);
                else lx(x),rx(x);
            else if(rs[y]==x)lx(y),lx(x);
                else rx(x),lx(x);
        }
        else
        {
            if(ch[y])pd(y);
            if(ls[y]==x)rx(x);
            else lx(x);
        }
    }
    if(f[x]==0)root=x;
}
int gk(int k)
{
    if(k==0)return 0;
    si[0]=0;
    int p=root;
    while(p)
    {
        if(ch[p])pd(p);
        if(si[ls[p]]+1==k)break;
        if(si[ls[p]]<k)k-=si[ls[p]]+1,p=rs[p];
        else p=ls[p];
    }
    return p;
}
vector <int> ans1;
int dp[4005][2][2];
int main() {
    R(T);
    int n, m;
    int a[100005];
    while(T-- ){
      R(n);
      int tn = n * 2;

      for(int i = 1;i <= tn; ++i) {
        R(a[i]);
        dp[i][0][0] = dp[i][1][0] = 0;
        dp[i][0][1] = dp[i][1][1] = 0;
      }
      int last = 0, lastnum = 0;
      int tot = 0 ;
      bool pd = 0;
      bool opt = 0;
      dp[0][0][0] = dp[0][1][0] = 1;
      for(int i = 1; i <= tn; ++i) {
          if(a[i] > lastnum) {
              lastnum = a[i];
              tot = i - last;
              for(int j = i; j >= 0; --j) {
              	if(j >= tot)
                  dp[j][0][opt ^ 1] |= dp[j - tot][0][opt];
                if(j >= tot - 1)
                  dp[j][1][opt ^ 1] |= dp[j - tot + 1][0][opt];
                  dp[j][1][opt ^ 1] |= dp[j][1][opt];
                if(j >= 1)
                  dp[j][0][opt ^ 1] |= dp[j - 1][1][opt];
              }
              for(int j = 0; j <= tn; ++j) {
                  dp[j][0][opt] = dp[j][1][opt] = 0;
              }
              opt ^= 1;
            /*  printf("i = %d\n", i);
              for(int m = 1; m <= n; ++m) {
                printf("dp[%d][%d][%d] = %d\n", m, 0,opt, dp[m][0][opt]);
                printf("dp[%d][%d][%d] = %d\n", m, 1, opt,dp[m][1][opt]);
             }*/
              last = i;
          }
      }
      tot = tn - last;
      if((n >= tot && dp[n - tot][0][opt]) || dp[n][1][opt]) pd = 1;
     /* for(int i = 1; i <= n; ++i) {
          printf("dp[%d][%d][%d] = %d\n", i, 0,opt, dp[i][0][opt]);
          printf("dp[%d][%d][%d] = %d\n", i, 1, opt,dp[i][1][opt]);
      }*/
      if(pd) {
          puts("YES");
      } else {
          puts("NO");
      }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 4e3 + 10;
vector<int> vec;
int n, m, r;
int a[maxn];
bool used[maxn];
int dp[maxn][maxn];///yes = 1, no = 0, not check = -1;
int dfs(int pos, int num){
	if(dp[pos][num] >= 0) return dp[pos][num];
	if(pos == r){
		return num == n;
	}
	return dp[pos][num] = dfs(pos + 1, num + vec[pos]) || dfs(pos + 1, num);
}///决策第pos个元素时, 个数为num
void print(){
	for(auto &itm : vec){
		cout << "=" << itm << endl;
	}
}
int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		vec.clear();
		scanf("%d", &n); m = n * 2;
		for(int i = 1; i <= m; i++){
			scanf("%d", &a[i]); used[i] = false;
		}
		int p, i, num; p = i = m; num = 0;
		while(i >= 1){
			num++; used[a[i]] = true;
			if(a[i] == p){
				vec.push_back(num);
				num = 0;
				while(p >= 1 && used[p]) p--;
			}
			i--;
		}
		r = vec.size();
		//print();
		for(int i = 0; i <= r; i++){
			for(int j = 0; j <= m; j++){
				dp[i][j] = -1;
			}
		}
		if(dfs(0, 0)) puts("YES");
		else puts("NO");
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 4e3 + 10;
vector<int> vec;
int n, m, r;
int a[maxn];
bool used[maxn];
int dp[maxn][maxn];///yes = 1, no = 0, not check = -1;
int dfs(int pos, int num){
	if(dp[pos][num] >= 0) return dp[pos][num];
	if(pos == r){
		return num == n;
	}
	return dp[pos][num] = dfs(pos + 1, num + vec[pos]) || dfs(pos + 1, num);
}///决策第pos个元素时, 个数为num
int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		vec.clear();
		scanf("%d", &n); m = n * 2;
		for(int i = 1; i <= m; i++){
			scanf("%d", &a[i]); used[i] = false;
		}
		int p, i, num; p = i = m; num = 0;
		while(i >= 1){
			num++; used[a[i]] = true;
			if(a[i] == p){
				vec.push_back(num);
				num = 0;
				while(p >= 1 && used[a[p]]) p--;
			}
			i--;
		}
		r = vec.size();
		for(int i = 0; i <= r; i++){
			for(int j = 0; j <= m; j++){
				dp[i][j] = -1;
			}
		}
		if(dfs(0, 0)) puts("YES");
		else puts("NO");
	}
	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
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int >
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 4e3 + 10 ;

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

vector <int > seg ;
int a[5000] , mark[mxn] , n , dp[mxn][mxn];
int mex(){
	for (int i = 2*n ; i >=1 ; i--){
		if (!mark[i])
			return i ;
	}
}

int main(){
	migmig
	int t ;
	cin>>t ;
	while (t--){
		seg.clear() ;
		fill(mark , mark + mxn , 0 ) ;
		cin>>n ;
		for (int i = 0 ; i <=n; i++)
			for (int j = 0 ; j <= n ; j++)
				dp[i][j] = 0 ;
		for (int i = 1 ; i <= 2*n ; i++)
			cin>>a[i] ;
		int se = 2*n , pas = 2*n + 1 ;
		for (int i = 2*n ; i >= 1 ; i--){
			mark[a[i]] = 1 ;
			if (a[i]==se){
				seg.push_back(pas - i) ;
				pas = i ;
				se = mex() ;
			}
		}
		dp[0][0] = 1 ;
		dp[0][seg[0]] = 1 ;
		for (int i = 1 ; i < seg.size() ; i++){
			dp[i][0] = 1 ;
			for (int j = 1 ; j <= n ; j++){
				dp[i][j] |= dp[i-1][j] ;
				if(j >= seg[i] )
					dp[i][j] |= dp[i-1][j - seg[i]] ;
				//cout<<i<<" , "<<j<<" : "<<dp[i][j]<<endl ;
			}
		}
		if (dp[seg.size()-1][n])
			cout<<"YES"<<"\n" ;
		else
			cout<<"NO"<<"\n" ;
	}
}


#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
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int >
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 4e3 + 10 ;

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

vector <int > seg ;
int a[5000] , mark[mxn] , n , dp[mxn][mxn];
int mex(){
	for (int i = 2*n ; i >=1 ; i--){
		if (!mark[i])
			return i ;
	}
}

int main(){
	migmig
	int t ;
	cin>>t ;
	while (t--){
		seg.clear() ;
		for (int i = 0 ; i <mxn ; i++)
			for (int j = 0 ; j < mxn ; j++)
				dp[i][j] = 0 ;
		fill(mark , mark + mxn , 0 ) ;
		cin>>n ;
		for (int i = 1 ; i <= 2*n ; i++)
			cin>>a[i] ;
		int se = 2*n , pas = 2*n + 1 ;
		for (int i = 2*n ; i >= 1 ; i--){
			mark[a[i]] = 1 ;
			if (a[i]==se){
				seg.push_back(pas - i) ;
				pas = i ;
				se = mex() ;
			}
		}
		dp[0][0] = 1 ;
		dp[0][seg[0]] = 1 ;
		for (int i = 1 ; i < seg.size() ; i++){
			dp[i][0] = 1 ;
			for (int j = 1 ; j <= n ; j++){
				if(j >= seg[i] )
					dp[i][j] += dp[i-1][j - seg[i]] + dp[i-1][j] ;
				//cout<<i<<" , "<<j<<" : "<<dp[i][j]<<endl ;
			}
		}
		if (dp[seg.size()-1][n])
			cout<<"YES"<<"\n" ;
		else
			cout<<"NO"<<"\n" ;
	}
}


#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
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int >
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 4e3 + 10 ;

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

vector <int > seg ;
int a[5000] , mark[mxn] , n , dp[mxn][mxn];
int mex(){
	for (int i = 2*n ; i >=1 ; i--){
		if (!mark[i])
			return i ;
	}
}

int main(){
	migmig
	int t ;
	cin>>t ;
	while (t--){
		seg.clear() ;
		fill(mark , mark + mxn , 0 ) ;
		cin>>n ;
		for (int i = 0 ; i <=n; i++)
			for (int j = 0 ; j <= n ; j++)
				dp[i][j] = 0 ;
		for (int i = 1 ; i <= 2*n ; i++)
			cin>>a[i] ;
		int se = 2*n , pas = 2*n + 1 ;
		for (int i = 2*n ; i >= 1 ; i--){
			mark[a[i]] = 1 ;
			if (a[i]==se){
				seg.push_back(pas - i) ;
				pas = i ;
				se = mex() ;
			}
		}
		dp[0][0] = 1 ;
		dp[0][seg[0]] = 1 ;
		for (int i = 1 ; i < seg.size() ; i++){
			dp[i][0] = 1 ;
			for (int j = 1 ; j <= n ; j++){
				if(j >= seg[i] )
					dp[i][j] += dp[i-1][j - seg[i]] | dp[i-1][j] ;
				//cout<<i<<" , "<<j<<" : "<<dp[i][j]<<endl ;
			}
		}
		if (dp[seg.size()-1][n])
			cout<<"YES"<<"\n" ;
		else
			cout<<"NO"<<"\n" ;
	}
}


#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
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int >
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 4e3 + 10 ;

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

vector <int > seg ;
int a[5000] , mark[mxn] , n , dp[mxn][mxn];
int mex(){
	for (int i = 2*n ; i >=1 ; i--){
		if (!mark[i])
			return i ;
	}
}

int main(){
	migmig
	int t ;
	cin>>t ;
	while (t--){
		seg.clear() ;
		fill(mark , mark + mxn , 0 ) ;
		cin>>n ;
		for (int i = 0 ; i <=n; i++)
			for (int j = 0 ; j <= n ; j++)
				dp[i][j] = 0 ;
		for (int i = 1 ; i <= 2*n ; i++)
			cin>>a[i] ;
		int se = 2*n , pas = 2*n + 1 ;
		for (int i = 2*n ; i >= 1 ; i--){
			mark[a[i]] = 1 ;
			if (a[i]==se){
				seg.push_back(pas - i) ;
				pas = i ;
				se = mex() ;
			}
		}
		dp[0][0] = 1 ;
		dp[0][seg[0]] = 1 ;
		for (int i = 1 ; i < seg.size() ; i++){
			dp[i][0] = 1 ;
			for (int j = 1 ; j <= n ; j++){
				if(j >= seg[i] )
					dp[i][j] |= dp[i-1][j - seg[i]] | dp[i-1][j] ;
				//cout<<i<<" , "<<j<<" : "<<dp[i][j]<<endl ;
			}
		}
		if (dp[seg.size()-1][n])
			cout<<"YES"<<"\n" ;
		else
			cout<<"NO"<<"\n" ;
	}
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    int e[maxn*2];//����ÿ�γ���
    //vector<int> e;
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        dp[i]=0;
    }
    int i=1,j,cnt=0;
    while(i<=m){
        j=i+1;
        while(p[i]>p[j]&&j<=m)j++;
        e[cnt++]=j-i;
        i=j;
    }
    dp[0]=1;
    for(int i=0;i<cnt;i++){
        for(int j=n;j>=e[i];j--)dp[j]|=dp[j-e[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    set<int> s;
    int a[maxn];//����ÿ�γ���
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        s.insert(i);
        dp[i]=0;
    }
    int cnt=0,r=m+1;
    while(s.size()){
        int mx=b[*s.rbegin()];
        a[cnt++]=abs(mx-r);
        for(int i=mx;i<r;i++)s.erase(p[i]);
        r=mx;
    }
    //memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<cnt;i++){
        for(int j=n;j>=a[i];j--)dp[j]|=dp[j-a[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    set<int> s;
    int a[maxn];//保存每段长度
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        s.insert(i);
        dp[i]=0;
    }
    int cnt=0,r=m+1;
    while(s.size()){
        int mx=b[*s.rbegin()];
        a[cnt++]=r-mx;
        for(int i=mx;i<r;i++)s.erase(p[i]);
        r=mx;
    }
    //memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<cnt;i++){
        for(int j=n;j>=a[i];j--)dp[j]|=dp[j-a[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    set<int> s;
    //int a[maxn];//保存每段长度
    vector<int> e;
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        s.insert(i);
        dp[i]=0;
    }
    int r=m+1;
    while(s.size()){
        int mx=b[*s.rbegin()];
        e.push_back(r-mx);
        for(int i=mx;i<r;i++)s.erase(p[i]);
        r=mx;
    }
    //memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<m;i++){
        for(int j=n;j>=e[i];j--)dp[j]|=dp[j-e[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    int e[maxn*2];//����ÿ�γ���
    //vector<int> e;
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        dp[i]=0;
    }
    int i=1,j,cnt=0;
    while(i<=m){
        j=i+1;
        while(p[i]>p[j])j++;
        e[cnt++]=j-i;
        i=j;
    }
    dp[0]=1;
    for(int i=0;i<cnt;i++){
        for(int j=n;j>=e[i];j--)dp[j]|=dp[j-e[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=2000+10;
int p[maxn*2],b[maxn*2];
int dp[2*maxn],n,m;
void solve(){
    cin>>n;
    int e[maxn*2];//保存每段长度
    //vector<int> e;
    m=n*2;
    for(int i=1;i<=m;i++){
        cin>>p[i];
        b[p[i]]=i;
        dp[i]=0;
    }
    int i=1,j=1,cnt=0;
    while(i<=m){
        while(p[i]>=p[j])j++;
        e[cnt++]=j-i;
        i=j;
    }
    dp[0]=1;
    for(int i=0;i<cnt;i++){
        for(int j=n;j>=e[i];j--)dp[j]|=dp[j-e[i]];
    }
    if(dp[n])cout<<"YES\n";
    else cout<<"NO\n";
}
int main(){
    int T;cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


//
//  main.cpp
//  Unmerge
//
//  Created by Bryan on 21/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#define MAX 200005
using namespace std;

int main()
{
    int T;
    scanf ("%d",&T);
    while (T--)
    {
        long long N;
        scanf ("%lld",&N);
        long long max = 0;
        long long temp;
        vector<long long>s;
        long long cur = 0;
        for (int f = 0;f<2*N;f++)
        {
            scanf ("%lld",&temp);
            if (max<temp)
            {
                max = temp;
                s.push_back(cur);
                cur = 1;
                //cout<<max<<endl;
            }
            else
                cur++;

        }
        s.push_back(cur);
        long long id = s.size()-1;
        //cout<<id<<endl;
        long long dp[100][2005];
        memset(dp,0,sizeof(dp));
        for (long long f = 0; f<=id;f++)
        {
            for (long long g = 0; g<=N;g++)
            {
                if (f == 0 && g == 0)
                    dp[f][g] = 1;
                else
                {
                    if (g == 0)
                        dp[f][g] = 1;
                    if  (g>=s[f])
                    {
                        dp[f][g] |= dp[f-1][g-s[f]];
                        dp[f][g] |= dp[f-1][g];
                    }

                }

                //cout<<dp[f][g];
            }
           // cout<<endl;
        }

        if (dp[id][N] == 1)
            printf ("YES\n");
        else
            printf ("NO\n");
    }
}


//
//  main.cpp
//  Unmerge
//
//  Created by Bryan on 21/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#define MAX 200005
using namespace std;

int main()
{
    int T;
    scanf ("%d",&T);
    while (T--)
    {
        long long N;
        scanf ("%lld",&N);
        long long max = 0;
        long long temp;
        vector<long long>s;
        long long cur = 0;
        for (int f = 0;f<2*N;f++)
        {
            scanf ("%lld",&temp);
            if (max<temp)
            {
                max = temp;
                s.push_back(cur);
                cur = 1;
                //cout<<max<<endl;
            }
            else
                cur++;

        }
        s.push_back(cur);
        long long id = s.size()-1;
        //cout<<id<<endl;
        long long dp[2005];
        memset(dp,0,sizeof(dp));
        dp[0] = 1;
        for (long long f = 0; f<=id;f++)
        {
            for (long long g = N; g>=0;g--)
            {
                if (g>=s[f])
                    dp[g] |= dp[g-s[f]];

            }
           // cout<<endl;
        }

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


//
//  main.cpp
//  Unmerge
//
//  Created by Bryan on 21/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
#define MAX 200005
using namespace std;

int main()
{
    int T;
    scanf ("%d",&T);
    while (T--)
    {
        long long N;
        scanf ("%lld",&N);
        long long max = 0;
        long long temp;
        vector<long long>s;
        long long cur = 0;
        for (int f = 0;f<2*N;f++)
        {
            scanf ("%lld",&temp);
            if (max<temp)
            {
                max = temp;
                s.push_back(cur);
                cur = 1;
                //cout<<max<<endl;
            }
            else
                cur++;

        }
        s.push_back(cur);
        long long id = s.size()-1;
        //cout<<id<<endl;
        long long dp[100][2005];
        memset(dp,0,sizeof(dp));
        for (long long f = 0; f<=id;f++)
        {
            for (long long g = 0; g<=N;g++)
            {
                if (f == 0 && g == 0)
                    dp[f][g] = 1;
                else
                {
                    if (g == 0)
                        dp[f][g] = 1;
                    if  (g>=s[f])
                    {
                        dp[f][g] |= dp[f-1][g-s[f]];
                        dp[f][g] |= dp[f-1][g];
                    }

                }

                //cout<<dp[f][g];
            }
           // cout<<endl;
        }

        if (dp[id][N] == 1)
            printf ("YES\n");
        else
            printf ("NO\n");
    }
}


//
//  main.cpp
//  Unmerge
//
//  Created by Bryan on 21/07/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#define MAX 200005
using namespace std;

int main()
{
    int T;
    scanf ("%d",&T);
    while (T--)
    {
        long long N;
        scanf ("%lld",&N);
        long long max = 0;
        long long temp;
        vector<long long>s;
        long long cur = 0;
        for (int f = 0;f<2*N;f++)
        {
            scanf ("%lld",&temp);
            if (max<temp)
            {
                max = temp;
                s.push_back(cur);
                cur = 1;
                //cout<<max<<endl;
            }
            else
                cur++;

        }
        s.push_back(cur);
        long long id = s.size()-1;
        //cout<<id<<endl;
        long long dp[2005][2005];
        memset(dp,0,sizeof(dp));
        for (long long f = 0; f<=id;f++)
        {
            for (long long g = 0; g<=N;g++)
            {
                if (f == 0 && g == 0)
                    dp[f][g] = 1;
                else if  (f>0)
                {
                    if (g == 0)
                        dp[f][g] = 1;
                    else if  (g>=s[f])
                        dp[f][g] |= dp[f-1][g-s[f]];

                    dp[f][g] |= dp[f-1][g];

                }

                //cout<<dp[f][g];
            }
           // cout<<endl;
        }

        if (dp[id][N] == 1)
            printf ("YES\n");
        else
            printf ("NO\n");
    }
}


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

#define IOS    ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<int, bool> pib;

typedef vector<int> vi;
typedef vector<pii> vpii;

const int INF = 1e9 + 99;
const ll INFLL = 2e18;
const int MOD = 1e9 + 7;
const ll MODLL = 10e9 + 7;
const int N = 2000 + 10;

int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};
int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};

int p[2*N];
int dp[2*N][2*N][2];

int F(int i, int j, int n, int last = 0) {
    if (i == 0 && j == 0) return 1;

    int &ret = dp[i][j][last];
    if (ret != -1) return ret;

    int cnt = 0, mx = 0;
    for (int k=0; k<n; ++k)
        if (p[k] > mx) mx = p[k], cnt = 1;
        else ++cnt;

    ret = 0;
    if (cnt <= i && cnt <= j) {
        ret = F(i-cnt, j, n-cnt, last^1);
        if (!ret)
            ret = F(i, j-cnt, n-cnt, last^1);
    }
    else if (cnt <= i) ret = F(i-cnt, j, n-cnt, last^1);
    else if (cnt <= j) ret = F(i, j-cnt, n-cnt, last^1);

    return ret;
}

int main() {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;

        n += n;
        for (int i=0; i<n; ++i) cin >> p[i];

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

        if (F(n/2, n/2, n)) puts("YES");
        else puts("NO");
    }

    return 0;
}


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

#define IOS    ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<int, bool> pib;

typedef vector<int> vi;
typedef vector<pii> vpii;

const int INF = 1e9 + 99;
const ll INFLL = 2e18;
const int MOD = 1e9 + 7;
const ll MODLL = 10e9 + 7;
const int N = 2000 + 10;

int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};
int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};

int p[2*N];

int main() {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;

        for (int i=0; i<n+n; ++i) cin >> p[i];

        bool ok = true;
        int id;
        for (int i=n+n-1; i>=0; --i)
            if (p[i] == n+n) {
                id = i-n;
                break;
            }

        for (int i=0; i<id; ++i)
            if (p[i] > p[id]) ok = false;

        if (ok) puts("YES");
        else puts("NO");
    }

    return 0;
}


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

#define IOS    ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<int, bool> pib;

typedef vector<int> vi;
typedef vector<pii> vpii;

const int INF = 1e9 + 99;
const ll INFLL = 2e18;
const int MOD = 1e9 + 7;
const ll MODLL = 10e9 + 7;
const int N = 2000 + 10;

int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};
int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};

int p[2*N];

int F(int i, int j, int n, int last = 0) {
    if (i == 0 && j == 0) return 1;

    int cnt = 0, mx = 0;
    for (int k=0; k<n; ++k)
        if (p[k] > mx) mx = p[k], cnt = 1;
        else ++cnt;

    int res = 0;
    if (cnt <= i && cnt <= j) {
        res += F(i-cnt, j, n-cnt, last^1);
        if (!res)
            res += F(i, j-cnt, n-cnt, last^1);
    }
    else if (cnt <= i) res += F(i-cnt, j, n-cnt, last^1);
    else if (cnt <= j) res += F(i, j-cnt, n-cnt, last^1);

    return res;
}

int main() {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;

        n += n;
        for (int i=0; i<n; ++i) cin >> p[i];

        bool ok = F(n/2, n/2, n);

        if (ok) puts("YES");
        else puts("NO");
    }

    return 0;
}


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

#define IOS    ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<int, bool> pib;

typedef vector<int> vi;
typedef vector<pii> vpii;

const int INF = 1e9 + 99;
const ll INFLL = 2e18;
const int MOD = 1e9 + 7;
const ll MODLL = 10e9 + 7;
const int N = 2000 + 10;

int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};
int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};

int p[2*N];

int main() {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;

        n += n;
        for (int i=0; i<n; ++i) cin >> p[i];

        bool ok = true;
        int q = n/2, r = n/2, last = 0;
        while (q || r) {
            int cnt = 0, mx = 0;
            for (int i=0; i<n; ++i)
                if (p[i] > mx) mx = p[i], cnt = 1;
                else ++cnt;
            if (!last) {
                if (cnt <= r) r -= cnt, n -= cnt, last = 1;
                else if (cnt <= q) q -= cnt, n -= cnt;
                else ok = false;
            } else {
                if (cnt <= q) q -= cnt, n -= cnt, last = 0;
                else if (cnt <= r) r -= cnt, n -= cnt;
                else ok = false;
            }
            if (!ok) break;
        }

        if (ok) puts("YES");
        else puts("NO");
    }

    return 0;
}


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

#define IOS    ios_base::sync_with_stdio(0); cin.tie(0)

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<int, bool> pib;

typedef vector<int> vi;
typedef vector<pii> vpii;

const int INF = 1e9 + 99;
const ll INFLL = 2e18;
const int MOD = 1e9 + 7;
const ll MODLL = 10e9 + 7;
const int N = 2000 + 10;

int fx[8] = {+0, +0, +1, -1, +1, +1, -1, -1};
int fy[8] = {+1, -1, +0, +0, +1, -1, +1, -1};

int p[2*N];

int main() {
    int t, n;

    cin >> t;
    while (t--) {
        cin >> n;

        for (int i=0; i<n+n; ++i) cin >> p[i];

        bool ok = true;
        int id, c = 1;
        for (int i=n+n-1; i>=0; --i, ++c)
            if (p[i] == n+n) {
                id = i-n;
                break;
            }

        if (c > n) ok = false;

        for (int i=0; i<id; ++i)
            if (p[i] > p[id]) ok = false;

        if (ok) puts("YES");
        else puts("NO");
    }

    return 0;
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];
    memset(subset,0,sizeof(subset));

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[2*n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		set<int> u;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				u.ainsert(j.first);
			}else
				break;
			for(auto l:u)
				mp.erase(l);
		}
	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[2*n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				mp.erase(j.first);
			}else
				break;
		}
	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				mp.erase(j.first);
			}else
				break;
		}
	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];
    memset(subset,0,sizeof(subset));

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[2*n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		set<int> u;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				u.insert(j.first);
			}else
				break;
			for(auto l:u)
				mp.erase(l);
		}
	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];
    memset(subset,0,sizeof(subset));

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[2*n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		set<int> u;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				u.insert(j.first);
			}else
				break;
		}
		for(auto l:u)
			mp.erase(l);

	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}


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

const int max_size = 1e6+5;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 420;

bool isSubsetSum(int y[], int n, int sum)
{
    // The value of subset[i][j] will be true if
    // there is a subset of set[0..j-1] with sum
    // equal to i
    bool subset[n + 1][sum + 1];
    memset(subset,0,sizeof(subset));

    // If sum is 0, then answer is true
    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    // If sum is not 0 and set is empty,
    // then answer is false
    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    // Fill the subset table in botton up manner
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < y[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= y[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - y[i - 1]];
        }
    }

    /*   // uncomment this code to print table
     for (int i = 0; i <= n; i++)
     {
       for (int j = 0; j <= sum; j++)
          printf ("%4d", subset[i][j]);
       printf("\n");
     }*/

    return subset[n][sum];
}

void solve(int t){
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<2*n;i++)
		cin >> a[i];
	map<int,int> mp;
	for(int i=2*n-1;i>=0;i--){
		mp[a[i]]=1;
		set<int> u;
		for(auto j:mp){
			if(j.first<a[i]){
				mp[a[i]]+=j.second;
				u.insert(j.first);
			}else
				break;
		}
		for(auto l:u)
			mp.erase(l);

	}
	int b[mp.size()],l=0;
	for(auto j:mp)
		b[l++]=j.second;
	if (isSubsetSum(b, l, n))
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll t;
	cin >> t;
	for(int i=1;i<=t;i++){
		solve(i);
	}
}