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