#include <bits/stdc++.h>
using namespace std;
long long deg[100001];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < (N); i++) {
    int x;
    cin >> x;
    deg[x]++;
  }
  long long sum = 0;
  for (int i = 1; i <= (N); i++) {
    sum += i * deg[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); i++) {
    long long from, to;
    cin >> from >> to;
    sum -= deg[from] * from;
    sum -= deg[to] * to;
    deg[to] += deg[from];
    deg[from] = 0;
    sum += to * deg[to];
    cout << sum << endl;
  }
}
