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