#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(int argc, const char* argv[]) {
  int N;
  int A[100000] = {0};
  int Q;
  int B[100000];
  int C[100000];
  ll SUM = 0;
  cin >> N;
  for (int i = 0; i < (N); ++i) {
    int a;
    cin >> a;
    SUM += a;
    A[a]++;
  }
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < (Q); ++i) {
    int b = B[i];
    int c = C[i];
    SUM = SUM - B[i] * A[b];
    SUM = SUM + C[i] * A[b];
    A[c] += A[b];
    A[b] = 0;
    cout << SUM << endl;
  }
  return 0;
}
