#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, q;
  cin >> n;
  long long int a[n];
  long long int s = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  cin >> q;
  for (long long int j = 0; j < q; j++) {
    long long int x, y;
    cin >> x >> y;
    for (long long int i = 0; i < n; i++) {
      if (a[i] == x) {
        a[i] = y;
        s += a[i];
      } else {
        s += a[i];
      }
    }
    cout << s << endl;
    s = 0;
  }
}
