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