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
#include "dzilib.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << " " << p.second; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#define ASSERT(...) 42
#endif
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int oo = 1e9;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
template<class I> I rnd(I l,I r){return std::uniform_int_distribution<I>(l,r)(rng);}
int main() {
  int t = GetT();
  int q = GetQ();

  long long c = GetC();
  long long n = GetN();
  while(t--) {
    ll e = rnd(0LL,n/10);
    map<ll,int> mp;
    auto query = [&](ll v) -> ll {
      debug(v);
      if(mp.count(v)) return mp[v];
      else {
        auto res = Ask(v+e);
        return mp[v] =res;
      } 
    };
    ll md=0;

    array<bool,4> bad = {};
    // has 2^2 --> divisible by 3.
    // do iters, until one over
    
    
    while(count(all(bad),1)!=3) {
        int cnt[4] = {};
        for(int j=0;j<8;++j) if(!bad[j%4]) {
          cnt[j%4]+=query(j+md)%3==0;

        }
        for(int j=0;j<4;++j) {
          if(cnt[j]==0) bad[j]=1;
        }
        md+=8;
        
    }
    ll of = find(all(bad),0)-bad.begin();
    md+=of; 

    int LG =0;
    while((1LL<<LG)<n+e+md) LG++;
    for(int i=2;i<LG;i++) {
      int id=0;
      for(ll j = md;;j+=1LL<<i) {
          if(query(j)%(i+1)!=0 ) {
              if(id%2==1) {
                md+=1LL<<i;
              }
              break;
          }
          if(query(j)==2*(i+1)) {
              if(id%2==0) {
                md+=1LL<<i;
                
              }
              break;
          }
          id++;
      }
    }
    // md+hidden_x + e = 1LL<<47
    auto res = (1LL<<LG) - md - e;
    Answer(res);
  }
}