#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int D[100001];
  for (int i = 0; i < 100001; i++) D[i] = 0;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    D[tmp]++;
  }
  int Q;
  cin >> Q;
  int B[Q], C[Q];
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  long long Total[Q];
  for (int i = 0; i < Q; i++) {
    Total[i] = 0;
    D[C[i]] += D[B[i]];
    D[B[i]] = 0;
    for (int j = 0; j < 100001; j++) Total[i] += j * D[j];
  }
  for (int i = 0; i < Q; i++) cout << Total[i] << endl;
}
