#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
void rep(int &B, int &C, vi &A) {
  int sum = 0;
  for (int i = 0; i < A.size(); i++) {
    if (A[i] == B) A[i] = C;
    sum += A[i];
  }
  cout << sum << endl;
  return;
}
int main() {
  int i, N, Q;
  cin >> N;
  vi A(N);
  for (i = 0; i < N; i++) cin >> A[i];
  cin >> Q;
  for (i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    rep(B, C, A);
  }
}
