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