/*****Because Its Christmas******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end())
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
        lld t; cin>>t;
        while(t--){
         lld n; cin>>n;
         pls(n,a);
         lld xr=a[0];
         itr(i,1,n-1)  xr=xr^a[i];
         lld sum=accumulate(a,a+n,0);
       if(sum==2*xr){ cout<<0<<nl<<nl; continue;}
       else if((sum%2==0&&xr%2==0)||(sum%2!=0&&xr%2!=0)||(sum%2!=0&&xr%2==0)){
           lld fctr=1;
           while(true){
               lld ans=(fctr*sum)^xr;
               if(ans>fctr*sum){ fctr++; continue;}
               else{
                   cout<<3<<nl;
                   lld bb=fctr*sum-ans;
                   cout<<ans<<" "<<bb/2<<" "<<bb/2<<nl;
                   break;
               }
           }
       }
         else{
             lld fctr=1;
              while(true){
               lld ans=((fctr*sum)^xr)+1;
               if(ans>fctr*sum+1){ fctr++; continue;}
               else{
                   cout<<3<<nl;
                   lld bb=fctr*sum-ans;
                   cout<<ans<<" "<<bb/2<<" "<<bb/2<<nl;
                   break;
               }
           }
       }

        }
}


/*****Because Its Christmas******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end())
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
        lld t; cin>>t;
        while(t--){
         lld n; cin>>n;
         pls(n,a);
         lld xr=a[0];
         itr(i,1,n-1)  xr=xr^a[i];
         lld sum=accumulate(a,a+n,0);
       if(sum==2*xr){ cout<<0<<nl<<nl; continue;}
       else if((sum%2==0&&xr%2==0)||(sum%2!=0&&xr%2!=0)||(sum%2!=0&&xr%2==0)){
           lld fctr=1;
               lld ans=(fctr*sum)^xr;
                   cout<<3<<nl;
                   lld bb=fctr*sum-ans;
                   cout<<ans<<" "<<bb/2<<" "<<bb/2<<nl;

           }
         else{
             lld fctr=4;
               lld ans=((fctr*sum)^xr)+1;
                   cout<<3<<nl;
                   lld bb=fctr*sum+1-ans;
                   cout<<ans<<" "<<bb/2<<" "<<bb/2<<nl;
                    }

        }
}


/*****Because Its Christmas******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end())
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
        lld t; cin>>t;
        while(t--){
            lld n; cin>>n;
            lld sum=0,xr,x;
            cin>>xr;
            sum=xr;
            n--;
            while(n--){
                cin>>x;
                sum+=x;
                xr^=x;
            }
            if(sum==2*xr) cout<<0<<nl<<nl;
            else  cout<<2<<nl<<x<<" "<<s+x<<nl;
        }
}


/*****Because Its Christmas******/
#include<bits/stdc++.h>
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define lexichar(x,y)     lexicographical_compare(x,x+strlen(x),y,y+strlen(y)) //modify the ranges
#define lexistr(x,y)      lexicographical_compare(x.begin(),x.end(),y.begin(),y.end())
#define MOD               1000000007
#define pi                3.1415926536
#define tod               1
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;
template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}

int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
        lld t; cin>>t;
        while(t--){
         lld n; cin>>n;
         pls(n,a);
         lld xr=a[0];
         itr(i,1,n-1)  xr=xr^a[i];
         lld kk=accumulate(a,a+n,0);
         if(kk==2*xr){ cout<<0<<nl; cout<<nl; continue;}
         lld ans=kk^xr;
         cout<<1<<nl;  cout<<ans<<nl;
        }

}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	forEach(a) cin >> it;
	ll s = accumulate(a.begin(), a.end(), 0LL);
	ll allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	if (s > allXor) {
		ll add = (1LL << 59);
		if (s % 2 == 1) {
			add++;
		}
		s += add;
		allXor ^= (2 * add);
		ans.pb(add);
	} else if (s < allXor) {
		if (s % 2 == 1) {
			ans.pb(1);
			s++;
			allXor ^= 2;
		}
	}
	assert(s <= allXor);
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb(abs(s - allXor) / 2);
		ans.pb(abs(s - allXor) / 2);
	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	forEach(a) cin >> it;
	ll s = accumulate(a.begin(), a.end(), 0LL);
	ll allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	if (s > allXor) {
		ll add = (10000000000000000);
		if (s % 2 == 1) {
			add++;
		}
		s += add;
		allXor ^= (2 * add);
		ans.pb(add);
	} else if (s < allXor) {
		if (s % 2 == 1) {
			ans.pb(1);
			s++;
			allXor ^= 2;
		}
	}
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb(abs(s - allXor) / 2);
		ans.pb(abs(s - allXor) / 2);
	} else if (s > allXor) {
		/// s > allXor
		assert(false);

	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ull> a(n);
	forEach(a) cin >> it;
	ull s = accumulate(a.begin(), a.end(), 0ULL);
	ull allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	if (s > allXor) {
		ull add = (1ULL << 30);
		while (s + add > (allXor ^ (add * 2))) add *= 2;
		if (s % 2 == 1) {
			add++;
		}
		s += add;
		allXor ^= (2 * add);
		ans.pb(add);
	} else if (s < allXor) {
		if (s % 2 == 1) {
			ans.pb(1);
			s++;
			allXor ^= 2;
		}
	}
	assert(s <= allXor);
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb((allXor - s) / 2);
		ans.pb((allXor - s) / 2);
	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	//freopen("C.in", "r", stdin);
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ull> a(n);
	forEach(a) cin >> it;
	ull s = accumulate(a.begin(), a.end(), 0ULL);
	ull allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	if (s > allXor) {
		ull add = (1ULL << 30);
		loop {
			if ((s + s % 2 + add) <= (allXor ^ 2 * (add + s % 2))) break;
			add *= 2;
		}
		add = s % 2 + add;
		allXor = (allXor ^ 2 * (add));
		s = (s + add);
		ans.pb(add);
	} else if (s < allXor) {
		if (s % 2 == 1) {
			ans.pb(1);
			s++;
			allXor ^= 2;
		}
	}
	assert(s <= allXor);
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb((allXor - s) / 2);
		ans.pb((allXor - s) / 2);
	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ull> a(n);
	forEach(a) cin >> it;
	ull s = accumulate(a.begin(), a.end(), 0ULL);
	ull allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	{
		ull add = (1ULL << 30);
		loop {
			if ((s + s % 2 + add) <= (allXor ^ 2 * (add + s % 2))) break;
			add *= 2;
		}
		add = s % 2 + add;
		allXor = (allXor ^ 2 * (add));
		s = (s + add);
		ans.pb(add);
	}
	assert(s <= allXor);
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb((allXor - s) / 2);
		ans.pb((allXor - s) / 2);
	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#define FASTIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
//#define BZ
//#define PBDS
//#define POINT

#ifndef BZ
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("no-stack-protector")
#pragma GCC target ("tune=native")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("conserve-stack")
//#pragma GCC optimize ("no-stack-limit")
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
//using xll = __int128;
//using xld = __float128;
using str = string;
using pll = pair<ll, ll>;

#ifdef POINT
using point = complex<ll>;
#define x real
#define y imag
#endif

#ifdef PBDS
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//using namespace __gnu_pbds::detail;
template <class T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif

#define INF 0x7fffffffffffffffLL
#define BASE 1000000007LL // 3 * 10**9 + 19 // 998244353 - rev == pow(n + m, BASE - 2)
#define MAX(type) std::numeric_limits<type>::max()
#define MIN(type) std::numeric_limits<type>::min()

#define LOG(v) cout << #v << " " << v << "\n";

#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define forEach(c) for (auto &it : c)
#define loop while (true)
#define mp make_pair
#define mt make_tuple

template <class T>
void chMax(T &a, T b) {
	if (a < b) a = b;
}

template <class T>
void chMin(T &a, T b) {
	if (b < a) a = b;
}

inline ll divUp(ll a, ll b) {
	return (a + b - 1)/b;
}

bool bit(ll m, ll v) {
	return (m >> v) & 1;
}

void solve() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	forEach(a) cin >> it;
	ll s = accumulate(a.begin(), a.end(), 0LL);
	ll allXor = 0;
	forEach(a) allXor ^= it;
	allXor *= 2;
	vector<ll> ans;
	if (s > allXor) {
		ll add = (100000000000000000);
		if (s % 2 == 1) {
			add++;
		}
		s += add;
		allXor ^= (2 * add);
		ans.pb(add);
	} else if (s < allXor) {
		if (s % 2 == 1) {
			ans.pb(1);
			s++;
			allXor ^= 2;
		}
	}
	if (s < allXor) {
		assert(s % 2 == 0);
		ans.pb(abs(s - allXor) / 2);
		ans.pb(abs(s - allXor) / 2);
	}
	cout << ans.size() << "\n";
	forEach(ans) cout << it << " ";
	cout << "\n";
}

//#define LOCAL

int main() {
	FASTIO
#ifdef LOCAL
	auto start = std::chrono::system_clock::now();
#endif
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) solve();
#ifdef LOCAL
	auto end = std::chrono::system_clock::now();
	std::chrono::duration<ld> elapsed_seconds = end - start;
	cerr << "\ntime: " << elapsed_seconds.count() << " s\n";
#endif
	return 0;
}


#if defined(LOCAL)
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#endif
#include <math.h>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<int, int>;
using lu = unsigned long long;
using l = long long;
using vs = vector<string>;
using vii = vector<ii>;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vlu = vector<lu>;
using ll = pair<l, l>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using mll = unordered_map<l, l>;
using sl = unordered_set<l>;
const l      INF = numeric_limits<int>::max();
const double EPS = 1e-10;
const double PI = 3.14159265358979323846;
const l      e0 = 1, e3 = 1000, e5 = 100000, e6 = 10 * e5, e7 = 10 * e6,
        e8 = 10 * e7, e9 = 10 * e8, l0 = 0, l1 = 1, l2 = 2;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a, b, c) for (l a = l(b); a < l(c); a++)
#define B(a, b, c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream &in, ostream &out);
void solve_brute(istream &, ostream &);
bool interactive_judge(istream &, istream &, ostream &);
bool generate_random(l, ostream &);
bool solution_checker(istream &, istream &, istream &, ostream &);
int  main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  tst::test_init(argc, argv);
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _judge = interactive_judge;
  // _custom_solution_checker = solution_checker;
  tst::maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}
const l MOD = e9 + 7;  // end of template
const l MAX = 251;
void    solve(istream &in, ostream &out) {
  l n, q;
  in >> n >> q;
  string s;
  in >> s;
  vl v(n);
  F(i, 0, n) v[i] = s[i] - 'a';
  vvl next(26, vl(n, INF));
  next[v.back()][n - 1] = n - 1;
  B(i, 0, n - 1) {
    F(j, 0, 26) next[j][i] = next[j][i + 1];
    next[v[i]][i] = i;
  }
  auto fnext = [&](l i, l p) {
    if (p >= n) return INF;
    return next[i][p];
  };
  vvvl state(MAX, vvl(MAX, vl(MAX, -1)));
  state[0][0][0] = 0;
  vvl                  ss(3);
  function<l(l, l, l)> dp = [&](l x, l y, l z) {
    l &rr = state[x][y][z];
    if (rr != -1) return rr;
    rr = INF;
    if (x > 0) { rr = min(rr, fnext(ss[0][x - 1], dp(x - 1, y, z)) + 1); }
    if (y > 0) { rr = min(rr, fnext(ss[1][y - 1], dp(x, y - 1, z)) + 1); }
    if (z > 0) { rr = min(rr, fnext(ss[2][z - 1], dp(x, y, z - 1)) + 1); }
    return rr;
  };
  while (q--) {
    string op;
    l      p;
    char   c;
    in >> op >> p;
    p--;
    if (op == "+") {
      in >> c;
      ss[p].emplace_back(c - 'a');
    } else {
      switch (p) {
        case 0:
          F(i, 0, ss[1].size() + 1) F(j, 0, ss[2].size() + 1) {
            state[ss[0].size()][i][j] = -1;
          }
          break;
        case 1:
          F(i, 0, ss[0].size() + 1) F(j, 0, ss[2].size() + 1) {
            state[i][ss[1].size()][j] = -1;
          }
          break;
        case 2:
          F(i, 0, ss[0].size() + 1) F(j, 0, ss[1].size() + 1) {
            state[i][j][ss[2].size()] = -1;
          }
          break;
      }
      ss[p].pop_back();
    }
    if (dp(ss[0].size(), ss[1].size(), ss[2].size()) != INF) {
      out << "YES" << lf;
    } else {
      out << "NO" << lf;
    }
  }
}


#if defined(LOCAL)
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#endif
#include <math.h>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<int, int>;
using lu = unsigned long long;
using l = long long;
using vs = vector<string>;
using vii = vector<ii>;
using vl = vector<l>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vlu = vector<lu>;
using ll = pair<l, l>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using mll = unordered_map<l, l>;
using sl = unordered_set<l>;
const l      INF = numeric_limits<int>::max();
const double EPS = 1e-10;
const double PI = 3.14159265358979323846;
const l      e0 = 1, e3 = 1000, e5 = 100000, e6 = 10 * e5, e7 = 10 * e6,
        e8 = 10 * e7, e9 = 10 * e8, l0 = 0, l1 = 1, l2 = 2;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a, b, c) for (l a = l(b); a < l(c); a++)
#define B(a, b, c) for (l a = l(c) - 1; a >= l(b); a--)

void solve(istream &in, ostream &out);
void solve_brute(istream &, ostream &);
bool interactive_judge(istream &, istream &, ostream &);
bool generate_random(l, ostream &);
bool solution_checker(istream &, istream &, istream &, ostream &);
int  main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  tst::test_init(argc, argv);
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _judge = interactive_judge;
  // _custom_solution_checker = solution_checker;
  tst::maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}
const l MOD = e9 + 7;  // end of template
const l MAX = 251;
void    solve(istream &in, ostream &out) {
  l n, q;
  in >> n >> q;
  string s;
  in >> s;
  vl v(n);
  F(i, 0, n) v[i] = s[i] - 'a';
  vvl next(26, vl(n, INF));
  next[v.back()][n - 1] = n - 1;
  B(i, 0, n - 1) {
    F(j, 0, 26) next[j][i] = next[j][i + 1];
    next[v[i]][i] = i;
  }
  auto fnext = [&](l i, l p) {
    if (p >= n) return INF;
    return next[i][p];
  };
  vvvl state(MAX, vvl(MAX, vl(MAX, INF)));
  state[0][0][0] = 0;
  vvl                  ss(3);
  function<l(l, l, l)> dp = [&](l x, l y, l z) {
    l &rr = state[x][y][z];
    if (rr != INF) return rr;
    if (x > 0) { rr = min(rr, fnext(ss[0][x - 1], dp(x - 1, y, z)) + 1); }
    if (y > 0) { rr = min(rr, fnext(ss[1][y - 1], dp(x, y - 1, z)) + 1); }
    if (z > 0) { rr = min(rr, fnext(ss[2][z - 1], dp(x, y, z - 1)) + 1); }
    return rr;
  };
  while (q--) {
    string op;
    l      p;
    char   c;
    in >> op >> p;
    p--;
    if (op == "+") {
      in >> c;
      ss[p].emplace_back(c - 'a');
    } else {
      switch (p) {
        case 0:
          F(i, 0, ss[1].size() + 1) F(j, 0, ss[2].size() + 1) {
            state[ss[0].size()][i][j] = INF;
          }
          break;
        case 1:
          F(i, 0, ss[0].size() + 1) F(j, 0, ss[2].size() + 1) {
            state[i][ss[1].size()][j] = INF;
          }
          break;
        case 2:
          F(i, 0, ss[0].size() + 1) F(j, 0, ss[1].size() + 1) {
            state[i][j][ss[2].size()] = INF;
          }
          break;
      }
      ss[p].pop_back();
    }
    if (dp(ss[0].size(), ss[1].size(), ss[2].size()) != INF) {
      out << "YES" << lf;
    } else {
      out << "NO" << lf;
    }
  }
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	//if (n >= 100000) return 0;

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp.erase(key);
					}
			}

			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	unordered_map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;
			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp.erase(key);
					}
			}
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 251

int dp[MAXQ][MAXQ][MAXQ];

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	dp[0][0][0] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						dp[i][j][k] = INF;

						if ((i > 0) && (dp[i - 1][j][k] != INF)) dp[i][j][k] = min(dp[i][j][k], next[dp[i - 1][j][k]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[i][j - 1][k] != INF)) dp[i][j][k] = min(dp[i][j][k], next[dp[i][j - 1][k]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[i][j][k - 1] != INF)) dp[i][j][k] = min(dp[i][j][k], next[dp[i][j][k - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;
			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		if (dp[slen[0]][slen[1]][slen[2]] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	unordered_map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp.erase(key);
					}
			}

			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	unordered_map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	if (n >= 100000) return 0;

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp.erase(key);
					}
			}

			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1000

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;
			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	unordered_map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;
			slen[id]--;
			ss[id] = ss[id].substr(0, slen[id]);
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define INF 100000000
#define MAXQ 1002

int encode(int a, int b, int c) {
	return a * MAXQ * MAXQ + b * MAXQ + c;
}

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

	int n, q, i, j, k, a, b, c, id, id2, id3, key;
	string s;
	char op, ch;

	cin >> n >> q >> s;
	vector<vector<int>> next(n + 1, vector<int>(26, INF));
	for (i = n - 1; i >= 0; i--) {
		next[i] = next[i + 1];
		next[i][s[i] - 'a'] = i + 1;
	}

	unordered_map<int, int>  dp;
	dp[encode(0,0,0)] = 0;

	vector<int> slen(3, 0);
	vector<string> ss(3, "");

	while (q--) {
		cin >> op;
		if (op == '+') {
			cin >> id >> ch;
			id--;
			slen[id]++;
			ss[id] = ss[id] + ch;

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp[key] = INF;

						if ((i > 0) && (dp[key - MAXQ * MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ * MAXQ]][ss[0][i - 1] - 'a']);
						if ((j > 0) && (dp[key - MAXQ] != INF)) dp[key] = min(dp[key], next[dp[key - MAXQ]][ss[1][j - 1] - 'a']);
						if ((k > 0) && (dp[key - 1] != INF)) dp[key] = min(dp[key], next[dp[key - 1]][ss[2][k - 1] - 'a']);
					}
			}
		}
		else {
			cin >> id;
			id--;
			ss[id] = ss[id].substr(0, slen[id]);

			for (i = (id == 0) ? slen[0] : 0; i <= slen[0]; i++) {
				for (j = (id == 1) ? slen[1] : 0; j <= slen[1]; j++)
					for (k = (id == 2) ? slen[2] : 0; k <= slen[2]; k++) {
						key = encode(i, j, k);
						dp.erase(key);
					}
			}

			slen[id]--;
		}

		key = encode(slen[0], slen[1], slen[2]);
		if (dp[key] == INF)
			cout << "NO\n";
		else cout << "YES\n";
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	getchar();
	cin >> str;
	fill(last, last + apsz, n);
	_for(i, n, maxx)
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void update(int i, int j, int k,int &ans,char chh)
{
	int tra = chh - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	int up[4] = {0};
	int bot[4] = {0};
	_for(i, 1, 4)
	{
		if (nm == -1)
			bot[i] = up[i] = nn[i];
		else
		{
			up[i] = nn[i];
			bot[i] = 0;
		}
	}
	dp[0][0][0] = -1;
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				if (i == 0 && k == 0 && j == 0)
					continue;
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					update(i-1,j,k,ans,s[1][i-1]);
				if (j)
					update(i, j - 1, k,ans,s[2][j-1]);
				if (k)
					update(i, j, k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{

	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] == n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] == n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	getchar();
	cin >> str;
	fill(last, last + apsz, n);
	_for(i, n, maxx)
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void update(int i, int j, int k,int &ans,char chh)
{
	int tra = chh - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	int up[4] = {0};
	int bot[4] = {0};
	_for(i, 1, 4)
	{
		if (nm == i)
			bot[i] = up[i] = nn[i];
		else
		{
			up[i] = nn[i];
			bot[i] = 0;
		}
	}
	dp[0][0][0] = -1;
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				if (i == 0 && k == 0 && j == 0)
					continue;
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					update(i-1,j,k,ans,s[1][i-1]);
				if (j)
					update(i, j - 1, k,ans,s[2][j-1]);
				if (k)
					update(i, j, k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{

	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] == n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] == n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	getchar();
	cin >> str;
	fill(last, last + apsz, n);
	_for(i,n, 250 + 7)
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void update(int i, int j, int k,int &ans,char ch)
{
	int tra = ch - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	int up[4] = {0};
	int bot[4] = {0};
	dp[0][0][0] = -1;
	_for(i, 1, 4)
	{
		if (nm == i)
			up[i] = bot[i] = nn[nm];
		else
		{
			up[i] = nn[i];
			bot[i] = 0;
		}
	}
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					update(i-1,j,k,ans,s[1][i-1]);
				if (j)
					update(i, j - 1, k,ans,s[2][j-1]);
				if (k)
					update(i, j, k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{
	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		else if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] == n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] == n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	getchar();
	cin >> str;
	fill(last, last + apsz, n);
	_for(i,n,max(maxx,(ll)n+n))
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void update(int i, int j, int k,int &ans,char chh)
{
	int tra = chh - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	int up[4] = {0};
	int bot[4] = {0};
	_for(i, 1, 4)
	{
		if (nm == i)
			bot[i] = up[i] = nn[i];
		else
		{
			up[i] = nn[i];
			bot[i] = 0;
		}
	}
	dp[0][0][0] = -1;
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				if (i == 0 && k == 0 && j == 0)
					continue;
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					update(i-1,j,k,ans,s[1][i-1]);
				if (j)
					update(i, j - 1, k,ans,s[2][j-1]);
				if (k)
					update(i, j, k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{

	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] == n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] == n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	getchar();
	cin >> str;
	fill(last, last + apsz, n);
	_for(i,n,max(maxx,(ll)n+n))
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void upd(int i, int j, int k,int &ans,char chh)
{
	int tra = chh - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	ll up[4] = {0,0,0,0};
	ll bot[4] = { 0, 0, 0, 0 };
	_for(i, 1, 4)
	{
		if (nm == i)
			bot[i] = up[i] = (ll)nn[i];
		else
		{
			up[i] = (ll)nn[i];
			bot[i] = 0ll;
		}
	}
	dp[0][0][0] = -1;
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				if (i == 0 && k == 0 && j == 0)
					continue;
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					upd(i-1,j,k,ans,s[1][i-1]);
				if (j)
					upd(i,j - 1,k,ans,s[2][j-1]);
				if (k)
					upd(i,j,k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{

	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] >= n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] >= n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pll;
typedef pair<int, int>pii;
typedef pair<double, double>pdd;

const ll maxx = 250+ 7;
const ll maxn =300000+7;
const ll mod = 998244353;
const ll maxs = 5 * (1E5) + 7;
const ll maxm = 4e5 + 7;
const ll maxk = 1008 + 7;
const ll maxw = 100 + 7;
const ll maxh = 100 + 7;
const double pi = 3.1415926;
const ll ten = 10;
const int ooi = 1234567;
const ll ool = 1e18 + 7;
const ldb eps = 1e-8;
const int apsz = 26;

//#define __TREE
#ifdef __TREE
#define lc(xx) (xx<<1)
#define rc(xx) ((xx<<1)|1)
#endif

#define _for(i,a,b) for(int i=(a);i<(b);i++)
#define msz(ss) memset(ss,0,sizeof(ss))
#define msllz(ss) memset(ss,(ll)0,sizeof(ss))
#define mszull(ss) memset(ss,(ull)0,sizeof(ss))
#define _rep(i,a,b) for(int i=(a);i<=(b);i++)
#define _dep(i,a,b) for(ll i=(a);i>=(b);i--)
#define msllneg(ss) memset(ss,(ll)-1,sizeof(ss))
#define msitt(xx) memset(xx,1,sizeof(xx))
#define IO ios::sync_with_stdio(false);cout.tie(0);cin.tie(0)
#define init_int_dp(dp) memset(dp,-1,sizeof(dp))
#define init_ll_dp(dp) memset(dp,-1ll,sizeof(dp))

string str;
string s[4];
int ph[maxn][30];
int last[30];
int n,q;
int dp[maxx][maxx][maxx];
char op;
int nm;
char ch;
void init()
{
	cin >> n >> q;
	cin >> str;
	fill(last, last + apsz, n);
	_for(i,n,max(maxx,(ll)n+n))
	{
		_for(j, 0, apsz)
			ph[i][j] = n;
	}
	_dep(i,n-1,0)
	{
		last[str[i] - 'a'] = i;
		_for(j, 0, apsz)
			ph[i][j] = last[j];
	}
}

int nn[4];

void upd(int i, int j, int k,int &ans,char chh)
{
	int tra = chh - 'a';
	ans = min(ans,ph[dp[i][j][k]+1][tra]);
}

void update()
{
	ll up[4] = {0,0,0,0};
	ll bot[4] = { 0, 0, 0, 0 };
	_for(i, 1, 4)
	{
		if (nm == i)
			bot[i] = up[i] = (ll)nn[i];
		else
		{
			up[i] = (ll)nn[i];
			bot[i] = 0ll;
		}
	}
	dp[0][0][0] = -1;
	_rep(i, bot[1], up[1])
	{
		_rep(j, bot[2], up[2])
		{
			_rep(k,bot[3], up[3])
			{
				if (i == 0 && k == 0 && j == 0)
					continue;
				int &ans = dp[i][j][k];
				ans = n;
				if (i)
					upd(i-1,j,k,ans,s[1][i-1]);
				if (j)
					upd(i,j - 1,k,ans,s[2][j-1]);
				if (k)
					upd(i,j,k - 1,ans,s[3][k-1]);
			}
		}
	}
}

void solve()
{

	while (q--)
	{
		cin >> op >> nm;
		if (op == '+')
			cin >> ch;
		if (op == '-')
		{
			nn[nm]--;
			s[nm].pop_back();
			if (dp[nn[1]][nn[2]][nn[3]] >= n)
				cout << "NO\n";
			else
				cout << "YES\n";
			continue;
		}
		s[nm].push_back(ch);
		nn[nm]++;
		update();
		if (dp[nn[1]][nn[2]][nn[3]] >= n)
			cout << "NO\n";
		else
			cout << "YES\n";
	}
}

int main(void)
{
#ifdef OJ
	freopen("buffcraft.in", "r", stdin);
	freopen("a.txt", "w", stdout);
#endif
#ifdef TEST
	freopen("a.txt", "w", stdout);
#endif
	IO;
	init();
	solve();
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>

#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Dwn(i,a,b) for(register int i=a;i>=b;--i)
#define PY printf("YES\n")
#define PN printf("NO\n")
#define inf 0x7f7f7f

using namespace std;

const int N=1e5+5;
const int Nx=251;

int f[Nx][Nx][Nx];
int Suc=1,nf,ch[N][26],n,Q,L[5],opt;
string s[5];
char sU[N];

void read(int &v){
	v=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')v=v*10+c-'0',c=getchar();
}

void Work(int a,int b,int c){
	int &vl=f[a][b][c];
	vl=n+1;
	//cout<<s[2][L[2]]<<endl;
	if(a)vl=min(vl,ch[ f[a-1][b][c] ][ s[1][L[1]]-'a' ]);
	if(b)vl=min(vl,ch[ f[a][b-1][c] ][ s[2][L[2]]-'a' ]);
	if(c)vl=min(vl,ch[ f[a][b][c-1] ][ s[3][L[3]]-'a' ]);
}

int main(){
	//freopen("D.in","r",stdin);
	read(n); read(Q);
	scanf("%s",sU+1);
	For(i,0,25)ch[n][i]=ch[n+1][i]=n+1;
	Dwn(i,n-1,0){
		For(j,0,25)ch[i][j]=ch[i+1][j];
		ch[i][sU[i+1]-'a']=i+1;
	}
	s[1]=s[2]=s[3]=" ";
	f[0][0][0]=0;
	while(Q--){
		char c=getchar();
		while(c!='+'&&c!='-')c=getchar();
		read(opt);
		if(c=='-'){

			s[opt].erase(L[opt],1); L[opt]--;
		}else{
			c=getchar(); while(c<'a'||c>'z')c=getchar();
			s[opt]=s[opt]+c; L[opt]++;
			if(opt==1) For(i,0,L[2])For(j,0,L[3]){
				Work(L[1],i,j);
			}
			if(opt==2) For(i,0,L[1])For(j,0,L[3]){
				Work(i,L[2],j);
			}
			if(opt==3) For(i,0,L[1])For(j,0,L[2]){
				Work(i,j,L[3]);
			}
		}
		//For(i,1,3)cout<<s[i]<<endl;
		//cout<<L[1]<<" "<<L[2]<<" "<<L[3]<<" "<<f[L[1]][L[2]][L[3]]<<endl;
		if(f[L[1]][L[2]][L[3]]<=n)PY;
		else PN;
	}
	return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<algorithm>

#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Dwn(i,a,b) for(register int i=a;i>=b;--i)
#define PY printf("YES\n")
#define PN printf("NO\n")
#define inf 0x7f7f7f

using namespace std;

const int N=1e5+5;
const int Nx=251;

int f[Nx][Nx][Nx];
int Suc=1,nf,ch[N][26],n,Q,L[5],opt;
char sU[N];

void read(int &v){
	v=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')v=v*10+c-'0',c=getchar();
}

int main(){
	freopen("D.in","r",stdin);
	read(n); read(Q);
	scanf("%s",sU+1);
	For(i,0,25)ch[n][i]=n+1;
	Dwn(i,n-1,0){
		For(j,0,25)ch[i][j]=ch[i+1][j];
		ch[i][sU[i+1]-'a']=i+1;
	}
	memset(f,inf,sizeof(f)); nf=f[0][0][0]; f[0][0][0]=0;
	while(Q--){
		char c=getchar();
		while(c!='+'&&c!='-')c=getchar();
		read(opt);
		cout<<"---------------------------"<<endl;
		if(c=='-'){
			if(opt==1)For(i,0,L[2])For(j,0,L[3])f[L[1]][i][j]=nf;
			if(opt==2)For(i,0,L[1])For(j,0,L[3])f[i][L[2]][j]=nf;
			if(opt==3)For(i,0,L[1])For(j,0,L[2])f[i][j][L[3]]=nf;
			L[opt]--;
		}else{
			c=getchar(); while(c<'a'||c>'z')c=getchar();
			int cx=c-'a';
			if(opt==1) For(i,0,L[2])For(j,0,L[3]){
				int now=f[L[1]][i][j];
				if(now>n)continue;
				now=ch[now][cx];
				f[L[1]+1][i][j]=min(f[L[1]+1][i][j],now);
			}
			if(opt==2) For(i,0,L[1])For(j,0,L[3]){
				int now=f[i][L[2]][j];
				if(now>n)continue;
				now=ch[now][cx];
				f[i][L[2]+1][j]=min(f[i][L[2]+1][j],now);
			}
			if(opt==3) For(i,0,L[1])For(j,0,L[2]){
				int now=f[i][j][L[3]];
				if(now>n)continue;
				now=ch[now][cx];
				f[i][j][L[3]+1]=min(f[i][j][L[3]+1],now);
			}
			L[opt]++;
		}
		cout<<L[1]<<" "<<L[2]<<" "<<L[3]<<" "<<f[L[1]][L[2]][L[3]]<<endl;
		if(f[L[1]][L[2]][L[3]]<=n)PY;
		else PN;
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 100005;

int n, q, d, DP[253][253][253], M[MAXN][26], inda = 0, indb = 0, indc = 0;

char c, str[MAXN], A[3][253];

void init() {
	for (int i = 0; i < 253; i++) {
		for (int j = 0; j < 253; j++) {
			for (int k = 0; k < 253; k++) {
				DP[i][j][k] = -1;
			}
		}
	}

	DP[0][0][0] = 0;
}

void precompute() {
	for (int i = 0; i < 26; i++) {
		M[n - 1][i] = n;
	}

	M[n - 1][str[n - 1] - 'a'] = n - 1;

	for (int i = n - 2; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			M[i][j] = M[i + 1][j];
		}

		M[i][str[i] - 'a'] = i;
	}
}

int dp(int a, int b, int c) {
	if (DP[a][b][c] != -1) {
		return DP[a][b][c];
	}

	int& res = DP[a][b][c];
	res = n + 1;

	if (a > 0) {
		int dp1 = dp(a - 1, b, c);

		if (dp1 < n) {
			dp1 = M[dp1][A[0][a - 1] - 'a'] + 1;
			res = min(res, dp1);
		}
	}

	if (b > 0) {
		int dp2 = dp(a, b - 1, c);

		if (dp2 < n) {
			dp2 = M[dp2][A[1][b - 1] - 'a'] + 1;
			res = min(res, dp2);
		}
	}

	if (c > 0) {
		int dp3 = dp(a, b, c - 1);

		if (dp3 < n) {
			dp3 = M[dp3][A[2][c - 1] - 'a'] + 1;
			res = min(res, dp3);
		}
	}

	return res;
}

int main() {
	scanf("%d %d", &n, &q);
	scanf(" %s", str);
	precompute();
	init();

	while (q--) {
		scanf(" %c", &c);

		if (c == '+') {
			scanf("%d %c", &d, &c);

			if (d == 1) {
				A[0][inda++] = c;
			} else if (d == 2) {
				A[1][indb++] = c;
			} else {
				A[2][indc++] = c;
			}

			if (dp(inda, indb, indc) != n + 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		} else {
			scanf("%d", &d);

			if (d == 1) {
				inda--;
			} else if (d == 2) {
				indb--;
			} else {
				indc--;
			}

			if (DP[inda][indb][indc] != n - 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		}
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 100005;

int n, q, d, IND[3];

char str[MAXN], A[3][500], c;

bool try_find() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (i != j && j != k && i != k) {
					int index = n - 1;
					int indi = IND[i] - 1;
					int indj = IND[j] - 1;
					int indk = IND[k] - 1;

					while (index >= 0 && (indi >= 0 || indj >= 0 || indk >= 0)) {
						if (indi >= 0 && str[index] == A[i][indi]) {
							indi--;
						} else if (indj >= 0 && str[index] == A[j][indj]) {
							indj--;
						} else if (indk >= 0 && str[index] == A[k][indk]) {
							indk--;
						}

						index--;
					}

					if (indi == -1 && indj == -1 && indk == -1) {
						return true;
					}
				}
			}
		}
	}

	return false;
}

int main() {
	bool prev_true = false;
	scanf("%d %d", &n, &q);
	scanf(" %s ", str);

	while (q--) {
		scanf(" %c", &c);

		if (c == '+') {
			scanf("%d %c", &d, &c);

			A[d - 1][IND[d - 1]++] = c;

			if (try_find()) {
				prev_true = true;
				printf("YES\n");
			} else {
				prev_true = false;
				printf("NO\n");
			}
		} else {
			scanf("%d", &d);
			IND[d - 1]--;

			if (prev_true) {
				printf("YES\n");
			} else {
				if (try_find()) {
					prev_true = true;
					printf("YES\n");
				} else {
					printf("NO\n");
				}
			}
		}
	}

	return 0;
}


#include <stdio.h>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 100005;

int n, q, d, DP[253][253][253], M[MAXN][26], inda = 0, indb = 0, indc = 0;

char c, str[MAXN], A[3][253];

void init() {
	for (int i = 0; i < 253; i++) {
		for (int j = 0; j < 253; j++) {
			for (int k = 0; k < 253; k++) {
				DP[i][j][k] = -1;
			}
		}
	}

	DP[0][0][0] = 0;
}

void precompute() {
	for (int i = 0; i < 26; i++) {
		M[n - 1][i] = n;
	}

	M[n - 1][str[n - 1] - 'a'] = n - 1;

	for (int i = n - 2; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			M[i][j] = M[i + 1][j];
		}

		M[i][str[i] - 'a'] = i;
	}
}

int dp(int a, int b, int c) {
	if (DP[a][b][c] != -1) {
		return DP[a][b][c];
	}

	int& res = DP[a][b][c];
	res = n + 1;

	if (a > 0) {
		int dp1 = dp(a - 1, b, c);

		if (dp1 < n) {
			dp1 = M[dp1][A[0][a - 1] - 'a'] + 1;
			res = min(res, dp1);
		}
	}

	if (b > 0) {
		int dp2 = dp(a, b - 1, c);

		if (dp2 < n) {
			dp2 = M[dp2][A[1][b - 1] - 'a'] + 1;
			res = min(res, dp2);
		}
	}

	if (c > 0) {
		int dp3 = dp(a, b, c - 1);

		if (dp3 < n) {
			dp3 = M[dp3][A[2][c - 1] - 'a'] + 1;
			res = min(res, dp3);
		}
	}

	return res;
}

int main() {
	scanf("%d %d", &n, &q);
	scanf(" %s", str);
	precompute();
	init();

	while (q--) {
		scanf(" %c", &c);

		if (c == '+') {
			scanf("%d %c", &d, &c);

			if (d == 1) {
				A[0][inda++] = c;
			} else if (d == 2) {
				A[1][indb++] = c;
			} else {
				A[2][indc++] = c;
			}

			if (dp(inda, indb, indc) != n + 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		} else {
			scanf("%d", &d);

			if (d == 1) {
				inda--;
			} else if (d == 2) {
				indb--;
			} else {
				indc--;
			}

			if (DP[inda][indb][indc] != n + 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		}
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 100005;

int n, q, d, DP[253][253][253], M[MAXN][26], inda = 0, indb = 0, indc = 0;

char c, str[MAXN], A[3][253];

void init() {
	for (int i = 0; i < 253; i++) {
		for (int j = 0; j < 253; j++) {
			for (int k = 0; k < 253; k++) {
				DP[i][j][k] = -1;
			}
		}
	}

	DP[0][0][0] = 0;
}

void precompute() {
	for (int i = 0; i < 26; i++) {
		M[n - 1][i] = n;
	}

	M[n - 1][str[n - 1] - 'a'] = n - 1;

	for (int i = n - 2; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			M[i][j] = M[i + 1][j];
		}

		M[i][str[i] - 'a'] = i;
	}
}

int dp(int a, int b, int c) {
	if (DP[a][b][c] != -1) {
		return DP[a][b][c];
	}

	int& res = DP[a][b][c];
	res = n + 1;

	if (a > 0) {
		int dp1 = dp(a - 1, b, c);

		if (dp1 < n) {
			dp1 = M[dp1][A[0][a - 1] - 'a'] + 1;
			res = min(res, dp1);
		}
	}

	if (b > 0) {
		int dp2 = dp(a, b - 1, c);

		if (dp2 < n) {
			dp2 = M[dp2][A[1][b - 1] - 'a'] + 1;
			res = min(res, dp2);
		}
	}

	if (c > 0) {
		int dp3 = dp(a, b, c - 1);

		if (dp3 < n) {
			dp3 = M[dp3][A[2][c - 1] - 'a'] + 1;
			res = min(res, dp3);
		}
	}

	return res;
}

int main() {
	scanf("%d %d", &n, &q);
	scanf(" %s", str);
	precompute();
	init();

	while (q--) {
		scanf(" %c", &c);

		if (c == '+') {
			scanf("%d %c", &d, &c);

			if (d == 1) {
				A[0][inda++] = c;

				for (int i = 0; i < 253; i++) {
					for (int j = 0; j < 253; j++) {
						DP[inda][i][j] = -1;
					}
				}
			} else if (d == 2) {
				A[1][indb++] = c;

				for (int i = 0; i < 253; i++) {
					for (int j = 0; j < 253; j++) {
						DP[i][indb][j] = -1;
					}
				}
			} else {
				A[2][indc++] = c;

				for (int i = 0; i < 253; i++) {
					for (int j = 0; j < 253; j++) {
						DP[i][j][indc] = -1;
					}
				}
			}

			if (dp(inda, indb, indc) != n + 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		} else {
			scanf("%d", &d);

			if (d == 1) {
				inda--;
			} else if (d == 2) {
				indb--;
			} else {
				indc--;
			}

			if (dp(inda, indb, indc) != n + 1) {
				printf("YES\n");
			} else {
				printf("NO\n");
			}
		}
	}
	return 0;
}


#include <stdio.h>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

#pragma warning(disable : 6031)
#pragma warning(disable : 4101)

using namespace std;

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

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

const int MAXN = 100005;

int n, q, d, IND[3];

char str[MAXN], A[3][500], c;

bool try_find() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (i != j && j != k && i != k) {
					int index = n - 1;
					int indi = IND[i] - 1;
					int indj = IND[j] - 1;
					int indk = IND[k] - 1;

					while (index >= 0 && (indi >= 0 || indj >= 0 || indk >= 0)) {
						if (indi >= 0 && str[index] == A[i][indi]) {
							indi--;
						} else if (indj >= 0 && str[index] == A[j][indj]) {
							indj--;
						} else if (indk >= 0 && str[index] == A[k][indk]) {
							indk--;
						}

						index--;
					}

					if (indi == -1 && indj == -1 && indk == -1) {
						return true;
					}
				}
			}
		}
	}

	return false;
}

int main() {
	bool prev_true = false;
	scanf("%d %d", &n, &q);
	scanf(" %s ", str);

	while (q--) {
		scanf("%c", &c);

		if (c == '+') {
			scanf("%d %c ", &d, &c);

			A[d - 1][IND[d - 1]++] = c;

			if (try_find()) {
				prev_true = true;
				printf("YES\n");
			} else {
				prev_true = false;
				printf("NO\n");
			}
		} else {
			scanf("%d", &d);
			IND[d - 1]--;

			if (prev_true) {
				printf("YES\n");
			} else {
				if (try_find()) {
					prev_true = true;
					printf("YES\n");
				} else {
					printf("NO\n");
				}
			}
		}
	}

	return 0;
}


#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 987654321

char str[100001];
int nextAlpha[100000][26];

vector<int> r[3];
int dp[251][251][251];

void makeNext(int n) {
	for (int i = 0; i < 26; i++) {
		nextAlpha[n][i] = INF;

		for (int x = n - 1; x >= 0; x--) {
			if (str[x] == 'a' + i) nextAlpha[x][i] = x;
			else nextAlpha[x][i] = nextAlpha[x + 1][i];
		}
	}
}
void compute(int x, int y, int z) {
	int& res = dp[x][y][z] = INF;
	if (x && dp[x-1][y][z] < INF)
		res = min(res, nextAlpha[dp[x - 1][y][z] + 1][r[0][x - 1]]);
	if (y && dp[x][y-1][z] < INF)
		res = min(res, nextAlpha[dp[x][y - 1][z] + 1][r[1][y - 1]]);
	if (z && dp[x][y][z-1] < INF)
		res = min(res, nextAlpha[dp[x][y][z - 1] + 1][r[2][z - 1]]);
}

int main()
{
	int n, q, x;
	char c, sign;
	scanf("%d %d", &n, &q);
	scanf("%s", str);
	makeNext(n);
	dp[0][0][0] = -1;

	while (q--) {
		scanf(" %c %d", &sign, &x); x--;
		if (sign == '-') r[x].pop_back();
		else {
			scanf(" %c", &c);
			r[x].push_back(c - 'a');

			int s0 = (x == 0) ? r[0].size() : 0;
			int s1 = (x == 1) ? r[1].size() : 0;
			int s2 = (x == 2) ? r[2].size() : 0;

			for (int i = s0; i <= r[0].size(); i++) {
				for (int j = s1; j <= r[1].size(); j++) {
					for (int k = s2; k <= r[2].size(); k++)
						compute(i, j, k);
				}
			}
		}
		printf("%s\n", (dp[r[0].size()][r[1].size()][r[2].size()] < INF) ? "YES" : "NO");
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <string>
#include <fstream>
#include <stack>
#include <sstream>
#include <tuple>

using namespace std;

int dp[251][251][251];
int nx[123456][27];

void update1(int i, int j, int k, string& s)
{
    if (i > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i-1][j][k]+1][s[i-1]-'a']);
}

void update2(int i, int j, int k, string& s)
{
    if (j > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j-1][k]+1][s[j-1]-'a']);
}

void update3(int i, int j, int k, string& s)
{
    if (k > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j][k-1]+1][s[k-1]-'a']);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    for (int j = 0; j < 26; ++j)
        nx[s.size()][j] = s.size()+1;

    for (int i = max(size_t(113456), s.size() - 1); i >= 0; --i)
    {
        for (int j = 0; j < 26; ++j)
        {
            if (i >= s.size())
                nx[i][j] = s.size() + 1;
            else
            if (s[i] == 'a' + j)
                nx[i][j] = i;
            else
                nx[i][j] = nx[i+1][j];
        }
    }

    string a1, a2, a3;
    dp[0][0][0] = -1;
    while(q--)
    {
        int w;
        char z, l;
        cin >> z >> w;
        if (z == '+')
            cin >> l;
        auto a = a1.size() + (w == 1 ? (z == '+' ? 1 : -1) : 0);
        auto b = a2.size() + (w == 2 ? (z == '+' ? 1 : -1) : 0);
        auto c = a3.size() + (w == 3 ? (z == '+' ? 1 : -1) : 0);

        if (z == '+')
        {
            if (a != a1.size())
            {
                a1.push_back(l);
                b = 0;
                c = 0;
            }
            else
            {
                if (b != a2.size())
                {
                    a2.push_back(l);
                    a = c = 0;
                }
                else
                {
                    a3.push_back(l);
                    a = b = 0;

                }
            }

            for (auto i = a; i <= a1.size(); ++i)
            {
                for (auto j = b; j <= a2.size(); ++j)
                {
                    for (auto k = c; k <= a3.size(); ++k)
                    {
                        dp[i][j][k] = s.size() + 1;
                        update1(i,j,k,a1);
                        update2(i,j,k,a2);
                        update3(i,j,k,a3);
                        //cout << "dp[" << i << "][" << j << "][" << k << "]=" << dp[i][j][k] << endl;
                    }
                }
            }
        }
        else
        {
            if (w == 1)
                a1.pop_back();
            else if (w == 2)
                a2.pop_back();
            else
                a3.pop_back();
        }
        cout << (dp[a1.size()][a2.size()][a3.size()] <= int(s.size()) ? "YES" : "NO") << endl;
    }

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <string>
#include <fstream>
#include <stack>
#include <sstream>
#include <tuple>

using namespace std;

int dp[251][251][251];
int nx[123456][27];

void update1(int i, int j, int k, string& s)
{
    if (i > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i-1][j][k]+1][s[i-1]-'a']);
}

void update2(int i, int j, int k, string& s)
{
    if (j > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j-1][k]+1][s[j-1]-'a']);
}

void update3(int i, int j, int k, string& s)
{
    if (k > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j][k-1]+1][s[k-1]-'a']);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    for (int j = 0; j < 26; ++j)
        nx[s.size()][j] = s.size()+1;

    for (int i = max(size_t(113455), s.size() - 1); i >= 0; --i)
    {
        for (int j = 0; j < 26; ++j)
        {
            if (i >= s.size())
                nx[i][j] = s.size() + 1;
            else
            if (s[i] == 'a' + j)
                nx[i][j] = i;
            else
                nx[i][j] = nx[i+1][j];
        }
    }

    string a1, a2, a3;
    dp[0][0][0] = -1;
    while(q--)
    {
        int w;
        char z, l;
        cin >> z >> w;
        if (z == '+')
            cin >> l;
        auto a = a1.size() + (w == 1 ? (z == '+' ? 1 : -1) : 0);
        auto b = a2.size() + (w == 2 ? (z == '+' ? 1 : -1) : 0);
        auto c = a3.size() + (w == 3 ? (z == '+' ? 1 : -1) : 0);

        if (z == '+')
        {
            if (a != a1.size())
            {
                a1.push_back(l);
                b = 0;
                c = 0;
            }
            else
            {
                if (b != a2.size())
                {
                    a2.push_back(l);
                    a = c = 0;
                }
                else
                {
                    a3.push_back(l);
                    a = b = 0;

                }
            }

            for (auto i = a; i <= a1.size(); ++i)
            {
                for (auto j = b; j <= a2.size(); ++j)
                {
                    for (auto k = c; k <= a3.size(); ++k)
                    {
                        dp[i][j][k] = s.size() + 1;
                        update1(i,j,k,a1);
                        update2(i,j,k,a2);
                        update3(i,j,k,a3);
                        //cout << "dp[" << i << "][" << j << "][" << k << "]=" << dp[i][j][k] << endl;
                    }
                }
            }
        }
        else
        {
            if (w == 1)
                a1.pop_back();
            else if (w == 2)
                a2.pop_back();
            else
                a3.pop_back();
        }
        cout << (dp[a1.size()][a2.size()][a3.size()] <= s.size() ? "YES" : "NO") << endl;
    }

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <string>
#include <fstream>
#include <stack>
#include <sstream>
#include <tuple>

using namespace std;

int dp[251][251][251];
int nx[123456][27];

void update1(int i, int j, int k, string& s)
{
    if (i > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i-1][j][k]+1][s[i-1]-'a']);
}

void update2(int i, int j, int k, string& s)
{
    if (j > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j-1][k]+1][s[j-1]-'a']);
}

void update3(int i, int j, int k, string& s)
{
    if (k > 0)
        dp[i][j][k] = min(dp[i][j][k], nx[dp[i][j][k-1]+1][s[k-1]-'a']);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    for (int j = 0; j < 26; ++j)
        nx[s.size()][j] = s.size()+1;

    for (int i = max(size_t(255), s.size() - 1); i >= 0; --i)
    {
        for (int j = 0; j < 26; ++j)
        {
            if (i >= s.size())
                nx[i][j] = s.size() + 1;
            else
            if (s[i] == 'a' + j)
                nx[i][j] = i;
            else
                nx[i][j] = nx[i+1][j];
        }
    }

    string a1, a2, a3;
    dp[0][0][0] = -1;
    while(q--)
    {
        int w;
        char z, l;
        cin >> z >> w;
        if (z == '+')
            cin >> l;
        auto a = a1.size() + (w == 1 ? (z == '+' ? 1 : -1) : 0);
        auto b = a2.size() + (w == 2 ? (z == '+' ? 1 : -1) : 0);
        auto c = a3.size() + (w == 3 ? (z == '+' ? 1 : -1) : 0);

        if (z == '+')
        {
            if (a != a1.size())
            {
                a1.push_back(l);
                b = 0;
                c = 0;
            }
            else
            {
                if (b != a2.size())
                {
                    a2.push_back(l);
                    a = c = 0;
                }
                else
                {
                    a3.push_back(l);
                    a = b = 0;

                }
            }

            for (auto i = a; i <= a1.size(); ++i)
            {
                for (auto j = b; j <= a2.size(); ++j)
                {
                    for (auto k = c; k <= a3.size(); ++k)
                    {
                        dp[i][j][k] = s.size() + 1;
                        update1(i,j,k,a1);
                        update2(i,j,k,a2);
                        update3(i,j,k,a3);
                        //cout << "dp[" << i << "][" << j << "][" << k << "]=" << dp[i][j][k] << endl;
                    }
                }
            }
        }
        else
        {
            if (w == 1)
                a1.pop_back();
            else if (w == 2)
                a2.pop_back();
            else
                a3.pop_back();
        }
        cout << (dp[a1.size()][a2.size()][a3.size()] <= s.size() ? "YES" : "NO") << endl;
    }

}


/*
ID : moreda
PROG : contest TEMPLATE-1
LANG : Microsoft Visual C++ 2017
*/
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned char byte;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef vector<int> vi;
#define watch(x)                         cerr << (#x) << " : " << (x) << '\n'
#define ms(arr,val)                      memset(arr, val, sizeof(arr))
#define pb                               push_back
#define eb                               emplace_back
#define fo(iterator,first,last)          for(int iterator = (int)(first); iterator < (int)(last); ++iterator)
#define fe(instance,arr)                 for(auto instance : arr)
#define fr(iterator,first,last)          for(int iterator = (int)(last) - 1; iterator >= (int)(first); --iterator)
#define mp(first,second)		         make_pair(first, second)
#define x                                first
#define y                                second
#define pi                               3.14159265358979323846264338327950
#define ee                               2.71828182845904523536028747135266
#define sz(arr)                          ((int)arr.size())
#define all(arr)                         (arr).begin(), (arr).end()
template<typename T>inline T vmin(T v) { return v; }
template<typename T, typename... Args>inline T vmin(T first, Args... args) { return min(first, vmin(args...)); }
template<typename T>inline T vmax(T v) { return v; }
template<typename T, typename... Args>inline T vmax(T first, Args... args) { return max(first, vmax(args...)); }
template<typename T, typename... Args> inline void smin(T &x, Args... args) { x = vmin(x, args...); }
template<typename T, typename... Args> inline void smax(T &x, Args... args) { x = vmax(x, args...); }
const ld eps = 1e-15;
const int maxN = 1 * 250 + 5, mod = (int) 1e9 + 7, inf = (int)1e9 + 1;
const int maxNN = 1 * 100000 + 10;

int dp[maxN][maxN][maxN];
int first[26][maxNN];

int main() {
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, q;
	string s;
	string ss[3] = { "","","" };
	cin >> n >> q;
	cin >> s;
	fill(*first, *first + sizeof(first) / sizeof(int), n);
	fill(**dp, **dp + sizeof(dp) / sizeof(int), -1);
	//memset(first, n, 26 * maxN * sizeof(first[0][0]));
	//fill()
	fr(i, 0, n)
	{
		fo(j, 0, 26)
			first[j][i] = first[j][i + 1];
		first[s[i] - 'a'][i] = i;
	}
	while (q--) {
		char c, cc;
		int xx;
		cin >> c >> xx;
		int i0 = sz(ss[0]);
		int j0 = sz(ss[1]);
		int k0 = sz(ss[2]);
		if (c == '+') {
			cin >> cc;
			ss[xx - 1] += cc;

			int i1 = sz(ss[0]);
			int j1 = sz(ss[1]);
			int k1 = sz(ss[2]);
			fo(i, i0 == i1 ? -1 : i1 - 1, i1)
				fo(j, j0 == j1 ? -1 : j1 - 1, j1)
				fo(k, k0 == k1 ? -1 : k1 - 1, k1)
				dp[i + 1][j + 1][k + 1] = vmin((i >= 0 ? first[ss[0][i] - 'a'][dp[i][j + 1][k + 1] + 1] : n)
					, (j >= 0 ? first[ss[1][j] - 'a'][dp[i + 1][j][k + 1] + 1] : n)
					, (k >= 0 ? first[ss[2][k] - 'a'][dp[i + 1][j + 1][k] + 1] : n));

		}
		else
			ss[xx - 1].pop_back();

		if (dp[sz(ss[0])][sz(ss[1])][sz(ss[2])] < n)
			cout << "YES\n";
		else
			cout << "NO\n";
	}

	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do smth instead of nothing and stay organized
*/


/*
ID : moreda
PROG : contest TEMPLATE-1
LANG : Microsoft Visual C++ 2017
*/
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned char byte;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef vector<int> vi;
#define watch(x)                         cerr << (#x) << " : " << (x) << '\n'
#define ms(arr,val)                      memset(arr, val, sizeof(arr))
#define pb                               push_back
#define eb                               emplace_back
#define fo(iterator,first,last)          for(int iterator = (int)(first); iterator < (int)(last); ++iterator)
#define fe(instance,arr)                 for(auto instance : arr)
#define fr(iterator,first,last)          for(int iterator = (int)(last) - 1; iterator >= (int)(first); --iterator)
#define mp(first,second)		         make_pair(first, second)
#define x                                first
#define y                                second
#define pi                               3.14159265358979323846264338327950
#define ee                               2.71828182845904523536028747135266
#define sz(arr)                          ((int)arr.size())
#define all(arr)                         (arr).begin(), (arr).end()
template<typename T>inline T vmin(T v) { return v; }
template<typename T, typename... Args>inline T vmin(T first, Args... args) { return min(first, vmin(args...)); }
template<typename T>inline T vmax(T v) { return v; }
template<typename T, typename... Args>inline T vmax(T first, Args... args) { return max(first, vmax(args...)); }
template<typename T, typename... Args> inline void smin(T &x, Args... args) { x = vmin(x, args...); }
template<typename T, typename... Args> inline void smax(T &x, Args... args) { x = vmax(x, args...); }
const ld eps = 1e-15;
const int maxN = 1 * 250 + 5, mod = (int) 1e9 + 7, inf = (int)1e9 + 1;
const int maxNN = 1 * 100000 + 10;

int dp[maxN][maxN][maxN];
int first[26][maxNN];

int main() {
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, q;
	string s;
	string ss[3] = { "","","" };
	cin >> n >> q;
	cin >> s;
	fill(*first, *first + sizeof(first) / sizeof(int), n);
	fill(**dp, **dp + sizeof(dp) / sizeof(int), -1);
	//memset(first, n, 26 * maxN * sizeof(first[0][0]));
	//fill()
	fr(i, 0, n)
	{
		fo(j, 0, 26)
			first[j][i] = first[j][i + 1];
		first[s[i] - 'a'][i] = i;
	}
	while (q--) {
		char c, cc;
		int xx;
		cin >> c >> xx;
		int i0 = sz(ss[0]);
		int j0 = sz(ss[1]);
		int k0 = sz(ss[2]);
		if (c == '+') {
			cin >> cc;
			ss[xx - 1] += cc;
		}
		else
			ss[xx - 1].pop_back();

		int i1 = sz(ss[0]);
		int j1 = sz(ss[1]);
		int k1 = sz(ss[2]);
		fo(i, i0 == i1 ? -1 : i1 - 1, i1)
			fo(j, j0 == j1 ? -1 : j1 - 1, j1)
			fo(k, k0 == k1 ? -1 : k1 - 1, k1)
			dp[i + 1][j + 1][k + 1] = vmin((i >= 0 ? first[ss[0][i] - 'a'][dp[i][j + 1][k + 1] + 1] : n)
				, (j >= 0 ? first[ss[1][j] - 'a'][dp[i + 1][j][k + 1] + 1] : n)
				, (k >= 0 ? first[ss[2][k] - 'a'][dp[i + 1][j + 1][k] + 1] : n));

		if (dp[sz(ss[0])][sz(ss[1])][sz(ss[2])] < n)
			cout << "YES\n";
		else
			cout << "NO\n";
	}

	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do smth instead of nothing and stay organized
*/