#include <bits/stdc++.h>
using namespace std;
long long a[100010];
long long c[100010];
int main() {
  int n;
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    c[a[i]]++;
    sum += a[i];
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    sum -= c[x] * x;
    sum += c[x] * y;
    c[y] += c[x];
    c[x] = 0;
    printf("%d\n", sum);
  }
}
