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