#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int ai[n];
  int count[100001];
  for (int i = 0; i < 100001; i++) {
    count[i] = 0;
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    count[t]++;
  }
  for (int i = 0; i < 100001; i++) {
    sum += i * count[i];
  }
  int q;
  cin >> q;
  long long sums[q];
  for (int i = 0; i < q; i++) {
    int bi, ci;
    cin >> bi >> ci;
    sum -= bi * count[bi];
    count[ci] += count[bi];
    sum += ci * count[bi];
    count[bi] = 0;
    sums[i] = sum;
  }
  for (int i = 0; i < q; i++) {
    cout << sums[i] << endl;
  }
  return 0;
}
