#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MOD = 1000000007;
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  map<long long, vector<int>> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]].push_back(i);
  }
  long long q;
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    if (m.count(b[i])) {
      for (int j : m[b[i]]) {
        a[j] = c[i];
        m[c[i]].push_back(j);
      }
      m.erase(b[i]);
    }
    long long res = 0;
    for (int j = 0; j < n; j++) {
      res += a[j];
    }
    cout << res << endl;
  }
}
