#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  std::map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    m[a[i]]++;
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
    long long int second = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] == b[i]) a[j] = c[i];
      second += a[j];
    }
    cout << second << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
