#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  long long t, n, i, j, k, l, c, f;
  cin >> n;
  i = 1;
  vector<long long> a(n + 1);
  c = 0;
  map<long long, vector<long long>> m;
  while (i <= n) {
    cin >> a[i];
    c += a[i];
    if (m.find(a[i]) == m.end())
      m.insert({a[i], {i}});
    else
      m[a[i]].push_back(i);
    i++;
  }
  long long q, ind;
  cin >> q;
  while (q--) {
    cin >> j >> k;
    l = m[j].size();
    while (l > 0) {
      c -= j;
      c += k;
      ind = m[j][l - 1];
      if (m.find(k) == m.end())
        m.insert({k, {ind}});
      else
        m[k].push_back(ind);
      m[j].pop_back();
      l--;
    }
    m.erase(j);
    cout << c << "\n";
  }
  return 0;
}
