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