#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, q, i, j, k, l;
  cin >> n;
  int a[n + 2];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  while (q--) {
    int aa, b, sum = 0;
    cin >> aa >> b;
    for (i = 0; i < n; i++) {
      if (a[i] == aa) a[i] = b;
      sum += a[i];
    }
    cout << sum << endl;
  }
}
int main() {
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
