#include <bits/stdc++.h>
using namespace std;
int main() {
  long x;
  cin >> x;
  long y[x];
  for (long i = 0; i < x; i++) {
    cin >> y[i];
  }
  long Q;
  cin >> Q;
  long z[Q][2];
  for (long i = 0; i < Q; i++) {
    for (long j = 0; j < 2; j++) {
      cin >> z[i][j];
    }
  }
  for (long i = 0; i < Q; i++) {
    long sum = 0;
    for (long j = 0; j < x; j++) {
      if (z[i][0] == y[j]) {
        y[j] = z[i][1];
      }
    }
    for (long j = 0; j < x; j++) {
      sum += y[j];
    }
    cout << sum << endl;
  }
}
