#include <bits/stdc++.h>
using namespace std;
long long int xpow(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b % 2 == 0) {
    long long int k = xpow(a, b / 2);
    return k * k;
  }
  if (b % 2 != 0) return a * xpow(a, b - 1);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int cnt_b = m[b];
    sum = sum - cnt_b * b + cnt_b * c;
    m[b] = 0;
    m[c] += cnt_b;
    cout << sum << endl;
  }
  return 0;
}
