#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
int n;
int a[N];
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    a[x]++;
    sum += x;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    sum += (c - b) * a[b];
    printf("%d\n", sum);
    a[c] += a[b];
    a[b] = 0;
  }
  return 0;
}
