1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <map> 
#include <string>
#include <vector>  
#include <iostream> 
#include <sstream> 
#include <queue>
#include <algorithm>
#include <assert.h>


using namespace std;

#define ll long long
#define PB 		push_back
#define FOR(a,start,end) 	for(int a=int(start); a<int(end); a++)
#define INF 		INT_MAX
#define SORT(a) 	sort(a.begin(),a.end()) 
#define CL(a,x) 		memset(a,x,sizeof(a))
#define REP(a,x)	for(int a=0;a<x;a++)
#define REP1(a,x)	for(int a=1;a<=x;a++)
#define MP 		make_pair



typedef vector<ll>     vi;
typedef pair<ll, ll>     pii;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vector<ll> > vvi;
typedef vector<vector<string> > vvs;
typedef vector<pair<string, string> > vss;
typedef pair<string, string> pss;
typedef pair<ll, pii> ppii;
typedef vector<ppii> vppii;
typedef vector<vector<pii> > vvii;
typedef vector<vvi> vvvi;


ll  n, k, q, d, r, g, b, z, p, a, c;
char zn;
string wa;
vi vk, va, vb;
vvi vvk;

void fixed(int k) {
	for (int i = 0; i < (int)vvk[k].size(); i++) {
		va[vvk[k][i]] = -1;
	}
	vvk[k].clear();
}
void dod(int a, int b) {
	int k = (int)vvk.size();
	vk.clear();
	vk.push_back(min(a,b));
	vk.push_back(max(a,b));
	vvk.push_back(vk);
	va[a] = k;
	va[b] = k;
}
void ext(int k, int a) {
	int i1, i2, i0;
	i1 = 0; i2 = (int)vvk[k].size() - 1; i0 = (i1 + i2) / 2;
	if (vvk[k][i1] > a)
		vvk[k].insert(vvk[k].begin(), a);
	else if (vvk[k][i2] < a)
		vvk[k].push_back(a);
	else {
		while ((i2 - i1) > 1) {

			if (vvk[k][i0] > a)
				i2 = i0;
			else
				i1 = i0;
			i0 = (i1 + i2) / 2;
		}
		vvk[k].insert(vvk[k].begin() + i2, a);
	}
	
	va[a] = k;
}
void mer(int k1, int k2) {

	int i = 0; 
	int j = 0;
	while (j < (int)vvk[k2].size()) {
		while ((j<(int)vvk[k2].size())&&(vvk[k1][i] > vvk[k2][j]))
			j++;
		if (j == (int)vvk[k2].size()) {
			for (; i < (int)vvk[k1].size(); i++) {
				vvk[k2].push_back(vvk[k1][i]);
				va[vvk[k1][i]] = k2;
			}
			break;
		}
		vvk[k2].insert(vvk[k2].begin() + j, vvk[k1][i]);
		va[vvk[k1][i]] = k2;
		i++;
		if (i == (int)vvk[k1].size())
			break;
	}

	//vvk[k1].clear();
}
void usu(int k, int c) {
	int i1, i2, i0;
	i1 = 0; i2 = (int)vvk[k].size() - 1; i0 = (i1 + i2) / 2;
	if (vvk[k][i1] == c)
		vvk[k].erase(vvk[k].begin());
	else if (vvk[k][i2] == c)
		vvk[k].pop_back();
	else {
		while ((i2 - i1) > 1) {
			if (vvk[k][i0] == c)
				break;
			else if (vvk[k][i0] > c)
				i2 = i0;
			else
				i1 = i0;
			i0 = (i1 + i2) / 2;
		}
		
		vvk[k].erase(vvk[k].begin() + i0);
	}

	if ((int)vvk[k].size() == 1)
		va[vvk[k][0]] = 0;
	//vvk[k].clear();
}
int main() {
	//freopen("c:\\wojtek\\uva\\pa\\debug\\t1.in", "rt", stdin);
	//d = 1000000007;
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	//	while (1) {
	cin >> n>>q;
	vvk.clear();
	vb.clear();
	vvk.push_back(vb);
	va.assign(n + 1, 0);
	wa.clear();
	for (int i = 0; i < q; i++) {
		cin >> zn;
		if (zn == '+') {
			cin >> a >> b;
			if (a == b) {
				if (va[a] == 0)
					va[a] = -1;
				else {
					fixed(va[a]);
				}
			}
			else {
				if ((va[a] == 0) && (va[b] == 0)) {
					dod(a, b);
				}
				else if ((va[a] == 0) || (va[b] == 0)) {
					if (va[a] > 0)
						ext(va[a], b);
					else if (va[b] > 0)
						ext(va[b], a);
					else if (va[a] < 0) {
						va[b] = -1;
					}
					else
						va[a] = -1;
				}
				else {
					if (va[a] == va[b]) {
						fixed(va[a]);
					}
					else if (va[a] < 0) {
						fixed(va[b]);
					}
					else if (va[b] < 0)
						fixed(va[a]);
					else {
						mer(va[a], va[b]);
					}
				}
			}
		}
		else if (zn == '-') {
			cin >> c;
			if (va[c] == -1)
				va[c] = 0;
			else {
			//	fixed(va[c]);
				usu(va[c], c);
				va[c] = 0;
			}
		}
		else {
			cin >> c;
			if (va[c] == 0)
				wa += '0';
			else if (va[c] < 0)
				wa += '1';
			else
				wa += '?';
		}
	}
	

	cout << wa << '\n';



	//}

	return 0;

}