#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, i, j, k, s = 0;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  int b[q][2];
  for (i = 0; i < q; i++)
    for (j = 0; j < 2; j++) cin >> b[i][j];
  for (i = 0; i < q; i++) {
    s = 0;
    for (j = 0; j < n; j++) {
      if (a[j] == b[i][0]) a[j] = b[i][1];
    }
    for (k = 0; k < n; k++) s += a[k];
    cout << s << "\n";
  }
}
