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