#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n, q;
  long long int sum;
  cin >> n;
  int a[n];
  map<long long int, long long int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    long long int b1, c1;
    cin >> b1 >> c1;
    long long int value = m[b1];
    sum = sum - (b1 * value);
    sum = sum + (c1 * value);
    m[b1] = 0;
    m[c1] += value;
    cout << sum << endl;
  }
  return 0;
}
