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