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