#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<vector<int>> bc(q, vector<int>(2));
  for (int i = 0; i < q; ++i) cin >> bc[i][0] >> bc[i][1];
  for (int i = 0; i < q; ++i) {
    for (int j = 0; j < n; ++j) {
      if (a[j] == bc[i][0]) a[j] = bc[i][1];
    }
    cout << accumulate(a.begin(), a.end(), 0) << "\n";
  }
  return 0;
}
