#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main() {
const long mod = 1e9;
int n;
cin >> n;
set<long> S;
char c;
pair<int, long> prev = {0, 0};
for (int i = 0; i < n; ++i){
cin >> c;
if (c == '+'){
long x;
cin >> x;
if (prev.first){
S.insert((x + prev.second) % mod);
}
else {
S.insert(x);
}
prev.first = 0;
continue;
}
if (c == '?'){
long x;
cin >> x;
auto it1 = S.find(x);
prev.first = 1;
if (it1 != S.end()){
cout << x << endl;
prev.second = x;
}
else {
auto it2 = S.upper_bound(x);
if (it2 != S.end()){
cout << *it2 << endl;
prev.second = *it2;
}
else {
cout << -1 << endl;
prev.second = -1;
}
}
continue;
}
}
}
#include <array>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
int main() {
const long mod = 1e9;
int n;
cin >> n;
set<long> S;
char c;
pair<int, long> prev = {0, 0};
for (int i = 0; i < n; ++i){
cin >> c;
if (c == '+'){
long x;
cin >> x;
if (prev.first){
S.insert((x + prev.second) % mod);
}
else {
S.insert(x);
}
prev.first = 0;
continue;
}
if (c == '?'){
long x;
cin >> x;
auto it1 = S.find(x);
prev.first = 1;
if (it1 != S.end()){
cout << x << endl;
prev.second = x;
}
else {
auto it2 = S.upper_bound(x);
if (it2 != S.end()){
cout << *it2 << endl;
prev.second = *it2;
}
else {
cout << -1 << endl;
prev.second = -1;
}
}
continue;
}
}
}