#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i(1); i <= n; ++i) cin >> v[i];
  vector<long long> pre(n + 1);
  pre[1] = v[1];
  for (int i(2); i <= n; ++i) pre[i] = pre[i - 1] + v[i];
  map<int, int> mp;
  for (int i(1); i <= n; ++i) mp[v[i]]++;
  int q;
  cin >> q;
  long long sum = pre[n];
  while (q--) {
    int idx, val;
    cin >> idx >> val;
    auto cnt = mp[idx];
    sum -= (idx * mp[idx]);
    sum += (val * cnt);
    mp[idx] = 0;
    mp[val] += cnt;
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
  return 0;
}
