#include #include #include #include using namespace std; void solve() { string s; cin >> s; int x = 1; vector a; for (size_t i = 0; i < s.size(); ++i) { if (s[i] == '^') { a.push_back(x); x = 1; } else { x++; } } a.push_back(x); // for (auto x : a) cout << x << ' '; // cout << ": "; int ans[23] = {}; for (size_t i = 0; i < a.size(); ++i) { int x = a[i]; for (int j = 22; j >= 0; --j) { if (x & (1 << j)) { ans[j]++; } } } int r = 0; for (int i = 22; i > 0; --i) { if (ans[i]) { r |= 1 << i; for (int j = i - 1; j > 0; --j) { ans[j] += ans[i] - 1; } } } r ^= ans[0] & 1; cout << r << endl; } int main() { ios::sync_with_stdio(false); int T; cin >> T; while (T-- > 0) { solve(); } return 0; }