#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[100000] = {0};
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    sum += x;
  }
  long long int q;
  cin >> q;
  vector<long long int> v;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum += (a[b]) * (c - b);
    a[c] += a[b];
    a[b] = 0;
    v.push_back(sum);
  }
  for (auto i : v) {
    cout << i << endl;
  }
  return 0;
}
