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