#include <bits/stdc++.h>
using namespace std;
void aryan_p() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return;
}
int32_t main() {
  long long n;
  cin >> n;
  long long *a = new long long[n];
  ;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    auto val = find(a, a + n, b);
    while (val != a + n) {
      long long idx = val - a;
      a[idx] = c;
      val = find(a, a + n, b);
    }
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      sum += a[i];
    }
    cout << sum << "\n";
  }
  return 0;
}
