#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n;
unordered_map<ll, ll> freq;
ll p, sum=0;
for (int i=0; i<n; i++) {
cin >> p;
sum+=p;
freq[p]++; //how many dishes have the price p
}
cin >> q;
string s;
ll offset=0;
vector<ll> res(q);
for (int i=0; i<q; i++) {
cin >> s;
ll x,y;
if (s=="INFLATION") {
cin >> x;
offset+=x;
sum+=1LL*n*x;
}else {
cin >> x >> y; //x is the real/current value of some prices, but in freq we store the original values: real=stored+offset
//to access the proper real x price, we need to access the proper stored, so stored=real-offset=x-offset and when chaning with y, change should be y-offset
x-=offset; y-=offset;
if (freq.count(x)) { //check if there even are prices with the wanted value
ll cnt=freq[x];
sum+=1LL*(y-x)*cnt;
freq[y]+=cnt; //swtich them, now the value is y for all prices that were before x
freq.erase(x); //remove x, there aren't any x valued dishes now
}
}
res[i]=sum;
}
for (auto r: res) cout << r << '\n';
return 0;
}