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