#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int num[100005];
int main() {
  int n;
  scanf("%d", &n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    num[x]++;
    ans += x;
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int x, y;
    scanf("%d", &x);
    scanf("%d", &y);
    ans -= (num[x] * x);
    ans += (num[x] * y);
    num[y] += num[x];
    num[x] = 0;
    printf("%lld\n", ans);
  }
}
