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

static vector<int> p;
static int n;
static long long k;
static long long query_count = 0;

#define SEND_MINUS_ONE_AND_QUIT(...) do { \
    cout << -1 << endl; \
    cout.flush(); \
    quitf(_wa, __VA_ARGS__); \
} while (false)

//这个函数加上
void SYZOJ_registerInteraction(int argc, char *argv[]) {
    __testlib_ensuresPreconditions();
    //__testlib_set_testset_and_group(argc, argv);
    //TestlibFinalizeGuard::registered = true;

    testlibMode = _interactor;
    __testlib_set_binary(stdin);

    inf.init("input", _input);
    ouf.init(stdin, _output);
    ans.init("answer", _answer);

    resultName = "score.txt";
    appesMode = false;
}

int main(int argc, char **argv) {
    SYZOJ_registerInteraction(argc, argv);//这里改掉

    n = inf.readInt(3, 200000, "n");
    k = inf.readLong(0, 1000000000LL, "k");
    p.assign(n + 1, 0);

    vector<int> seen(n, 0);
    for (int i = 1; i <= n; ++i) {
        p[i] = inf.readInt(0, n - 1, "p_i");
        if (seen[p[i]]) {
            quitf(_fail, "bad test data: value %d appears more than once", p[i]);
        }
        seen[p[i]] = 1;
    }
    for (int x = 0; x < n; ++x) {
        if (!seen[x]) quitf(_fail, "bad test data: value %d is missing", x);
    }

    cout << n << ' ' << k << endl;
    cout.flush();

    while (true) {
        if (ouf.seekEof()) {
            quitf(_wa, "unexpected EOF before final answer after %lld queries", query_count);
        }

        string cmd = ouf.readToken();
        if (cmd == "?") {
            string op = ouf.readToken();
            long long li = ouf.readLong();
            long long lj = ouf.readLong();

            if (query_count >= k) {
                SEND_MINUS_ONE_AND_QUIT("too many queries: limit is %lld", k);
            }
            if (!(op == "and" || op == "or")) {
                SEND_MINUS_ONE_AND_QUIT("invalid query operator: %s", op.c_str());
            }
            if (li < 1 || li > n || lj < 1 || lj > n || li >= lj) {
                SEND_MINUS_ONE_AND_QUIT(
                    "invalid query indices: i=%lld j=%lld, expected 1 <= i < j <= n", li, lj);
            }

            ++query_count;
            int i = (int)li, j = (int)lj;
            int answer = (op == "and") ? (p[i] & p[j]) : (p[i] | p[j]);
            cout << answer << endl;
            cout.flush();
        } else if (cmd == "!") {
            vector<int> got(n + 1, 0);
            vector<int> used(n, 0);
            for (int i = 1; i <= n; ++i) {
                long long x = ouf.readLong();
                if (x < 0 || x >= n) {
                    quitf(_wa, "answer value out of range at position %d: %lld", i, x);
                }
                got[i] = (int)x;
                if (used[got[i]]) {
                    quitf(_wa, "answer is not a permutation: value %d appears more than once", got[i]);
                }
                used[got[i]] = 1;
            }
            if (!ouf.seekEof()) {
                quitf(_wa, "trailing output after final answer: %s", ouf.readToken().c_str());
            }
            for (int i = 1; i <= n; ++i) {
                if (got[i] != p[i]) {
                    quitf(_wa, "wrong answer at position %d: expected %d, found %d; queries=%lld",
                          i, p[i], got[i], query_count);
                }
            }
            quitf(_ok, "accepted with %lld queries", query_count);
        } else {
            SEND_MINUS_ONE_AND_QUIT("invalid command: %s", cmd.c_str());
        }
    }
}
