#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, m, t, q, c = 0;
  int a[10000];
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  while (q--) {
    cin >> j >> k;
    for (i = 0; i < n; i++) {
      if (a[i] == j) a[i] = k;
    }
    c = 0;
    for (i = 0; i < n; i++) {
      c += a[i];
    }
    cout << c << endl;
  }
  return 0;
}
