#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, i, x, j, mx = 0, t, k, b, a, ans = 0, c = 0;
  string s, str;
  char strn;
  cin >> n;
  long long int ara[n + 1], bra[n + 1], taj[n + 1];
  for (i = 1; i <= n; i++) cin >> ara[i];
  cin >> k;
  while (k--) {
    ans = 0;
    cin >> a >> b;
    for (i = 1; i <= n; i++) {
      if (ara[i] == a) ara[i] = b;
      ans += ara[i];
    }
    cout << ans << endl;
  }
  return 0;
}
