#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  long long b, c;
  while (q--) {
    cin >> b >> c;
    for (long long i = 0; i < n; i++) {
      if (b == a[i]) {
        a[i] = c;
      }
    }
    for (long long i = 0; i < n; i++) {
      sum += a[i];
    }
    cout << sum << endl;
    sum = 0;
  }
}
