#include <bits/stdc++.h>
using namespace std;
long long n, a[100100], b[100100], c[100100], tot = 0, q, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 1; i <= q; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
      tot += a[j];
    }
    cout << tot << endl;
    tot = 0;
  }
}
