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