#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int q;
  int array[100005] = {0};
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int data;
    cin >> data;
    array[data]++;
    sum += data;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    sum -= array[a] * a;
    sum += array[a] * b;
    array[b] += array[a];
    array[a] = 0;
    cout << sum << endl;
  }
  return (0);
}
