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