#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int i, j, n, m, q, a, b;
  scanf("%lld", &n);
  std::vector<long long int> v(n);
  long long int sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &v[i]);
    sum += v[i];
  }
  scanf("%lld", &q);
  while (q--) {
    scanf("%lld", &a);
    scanf("%lld", &b);
    for (long long int i = 0; i < n; ++i) {
      if (v[i] == a) {
        v[i] = b;
        sum = sum - a + b;
      }
    }
    cout << sum << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
