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