#include <bits/stdc++.h>
using namespace std;
int a[10010];
int cont[10010] = {};
int main() {
  int n, q, x, y;
  scanf("%d", &n);
  long total = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    cont[a[i]]++;
    total += a[i];
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &x, &y);
    total += (cont[x]) * (y - x);
    cont[y] += cont[x];
    cont[x] = 0;
    cout << total << endl;
  }
}
