#include <bits/stdc++.h>
using namespace std;
const int aa = 100000;
int main() {
  int N, Q, B, C, A;
  cin >> N;
  int ct[aa];
  for (int i = 0; i < aa; i++) {
    ct[i] = 0;
  }
  long long int total = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    total += A;
    ct[A]++;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    int temp = C - B;
    total += temp * ct[B];
    cout << total << endl;
    ct[C] += ct[B];
    ct[B] = 0;
  }
}
