#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t=1;
   // cin >> t;
    while (t--) {
        int q;
        cin >> q;

        vector<pair<int, int>> events;
        events.reserve(q);

        while (q--) {
            char op;
            cin >> op;
            if (op == '+' || op == '-') {
                int x, k;
                cin >> x >> k;
                if (op == '+') {
                    events.emplace_back(x, k);
                } else {
                    for (auto it = events.begin(); it != events.end(); ++it) {
                        if (it->first == x && it->second == k) {
                            events.erase(it);
                            break;
                        }
                    }
                }
            } else if (op == '?') {
                int ti;
                cin >> ti;
                long long ans = 0;
                for (const auto &ev: events) {
                    int x = ev.first;
                    int k = ev.second;
                    int d = (ti - 1) % (2 * k);
                    if (d < k) {
                        ans += x;
                    }
                }
                cout << ans << "\n";
            }
        }
    }

    return 0;
}
