#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int N, Q, buf;
  long long count[100000] = {};
  long long sum = 0;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < (int)N; i++) {
    cin >> buf;
    count[buf]++;
    sum += buf;
  }
  cin >> Q;
  int b[Q];
  int c[Q];
  for (int i = 0; i < (int)Q; i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (int)Q; i++) {
    count[c[i]] += count[b[i]];
    sum += count[b[i]] * (c[i] - b[i]);
    count[b[i]] = 0;
    cout << sum << endl;
  }
}
