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