#include <bits/stdc++.h>
using namespace std;
int A[100001];
long sum = 0;
int main(int argc, const char** argv) {
  int n = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A[a]++;
  }
  int q = 0;
  cin >> q;
  for (int i = 0; i < 100001; i++) {
    sum += A[i] * i;
  }
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum += A[b] * (c - b);
    A[c] += A[b];
    cout << sum << '\n';
  }
  return 0;
}
