#include <bits/stdc++.h>
using namespace std;
int counts[100005] = {0};
int main(int argc, char const *argv[]) {
  int count, operations;
  int sum = 0;
  int current, former, latter;
  cin >> count;
  for (int i = 0; i < count; ++i) {
    cin >> current;
    sum += current;
    counts[current]++;
  }
  cin >> operations;
  for (int i = 0; i < operations; ++i) {
    cin >> former >> latter;
    sum += (latter - former) * counts[former];
    counts[latter] += counts[former];
    counts[former] = 0;
    cout << sum << endl;
  }
  return 0;
}
