#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long n, b, c, q;
  cin >> n;
  long a[n];
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    long sum = 0;
    for (auto j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
      }
      sum = sum + a[j];
    }
    cout << sum << "\n";
  }
  return 0;
}
