#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long AN[100001] = {0};
  long long T = 0;
  for (int n = 0; n < N; n++) {
    int A;
    cin >> A;
    T = T + A;
    AN[A]++;
  }
  long long Q;
  cin >> Q;
  for (int n = 0; n < Q; n++) {
    long long B, C;
    cin >> B >> C;
    if (AN[B] != 0) {
      long long AB = AN[B];
      AN[C] = AN[C] + AB;
      T = T - AB * B + AB * C;
    }
    cout << T << endl;
  }
}
