#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
map<int, int> M;
int a[N];
int main() {
  int n, sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i], ++M[a[i]];
  }
  int q, a, b;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &a, &b);
    sum += M[a] * (b - a);
    M[b] += M[a], M[a] = 0;
    printf("%d\n", sum);
  }
}
