#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr);
int main() {
int t; cin>>t;
while(t--) {
int n; cin>>n;
ll temp;
map<ll,ll> pos;
for(int i = 0;i<n;i++) {
cin>>temp;
pos[temp] =i;
}
ll result = 0;
int q; cin>>q;
while(q--) {
ll type; cin>>type;
if(type == 1) {
ll k; cin>>k;
result +=k;
}
else {
ll x; cin>>x;
auto it = pos.find(x);
ll ans = -2;
if(it!=pos.end()) {
ans = it->second+result;
ans%=n;
ans+=n;
ans%=n;
}
cout<<ans+1<<endl;
}
}
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwoKCgojZGVmaW5lIEZBU1QgICAgIHN0ZDo6aW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IHN0ZDo6Y2luLnRpZShudWxscHRyKTsgc3RkOjpjb3V0LnRpZShudWxscHRyKTsKCgppbnQgbWFpbigpIHsKCiAgICBpbnQgdDsgIGNpbj4+dDsKICAgIHdoaWxlKHQtLSkgewogICAgICAgIGludCBuOyAgY2luPj5uOwogICAgICAgIGxsIHRlbXA7CiAgICAgICAgbWFwPGxsLGxsPiBwb3M7CiAgICAgICAgZm9yKGludCBpID0gMDtpPG47aSsrKSB7CiAgICAgICAgICAgIGNpbj4+dGVtcDsKICAgICAgICAgICAgcG9zW3RlbXBdID1pOwogICAgICAgIH0KICAgICAgICBsbCByZXN1bHQgPSAwOwogICAgICAgIGludCBxOyAgY2luPj5xOwogICAgICAgIHdoaWxlKHEtLSkgewogICAgICAgICAgICBsbCB0eXBlOyAgIGNpbj4+dHlwZTsKICAgICAgICAgICAgaWYodHlwZSA9PSAxKSB7CiAgICAgICAgICAgICAgICBsbCBrOyAgY2luPj5rOwogICAgICAgICAgICAgICAgcmVzdWx0ICs9azsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICAgIGxsIHg7ICBjaW4+Png7CiAgICAgICAgICAgICAgICBhdXRvIGl0ID0gcG9zLmZpbmQoeCk7CiAgICAgICAgICAgICAgICBsbCBhbnMgPSAtMjsKICAgICAgICAgICAgICAgIGlmKGl0IT1wb3MuZW5kKCkpIHsKICAgICAgICAgICAgICAgICAgICBhbnMgPSBpdC0+c2Vjb25kK3Jlc3VsdDsKICAgICAgICAgICAgICAgICAgICBhbnMlPW47CiAgICAgICAgICAgICAgICAgICAgYW5zKz1uOwogICAgICAgICAgICAgICAgICAgIGFucyU9bjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGNvdXQ8PGFucysxPDxlbmRsOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgIH0KICAgIHJldHVybiAwOwp9