#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  long long sum, M;
  vector<long long> A(N, 0);
  vector<int> num(100001);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 1; i < 100001; i++) {
    num[i] = count(A.begin(), A.end(), i);
  }
  sum = accumulate(A.begin(), A.end(), 0);
  int B, C, D;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    D = C - B;
    sum += D * num[B];
    num[C] += num[B];
    num[B] = 0;
    cout << sum << endl;
  }
  return 0;
}
