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