#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[i];
  int Q;
  cin >> Q;
  for (int j = 0; j < (Q); ++j) {
    int B, C;
    cin >> B >> C;
    ll sum = 0;
    for (int k = 0; k < (N); ++k) {
      if (A[k] == B) {
        A[k] = C;
      }
      sum += A[k];
    }
    cout << sum << endl;
  }
  return 0;
}
