#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(100001, 0);
  int count = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec[x]++;
    count += x;
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x;
    int y;
    cin >> x >> y;
    count += (y - x) * vec[x];
    cout << count << endl;
    vec[y] += vec[x];
    vec[x] = 0;
  }
}
