#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int Q, B, C, ans;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    ans = 0;
    cin >> B >> C;
    for (int j = 0; j < N; j++) {
      if (A.at(j) == B) {
        A.at(j) = C;
      }
      ans += A.at(j);
    }
    cout << ans << endl;
  }
}
