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