#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, q;
int freq[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    sum += x;
    freq[x]++;
  }
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= freq[a] * a;
    sum += freq[a] * b;
    freq[b] += freq[a];
    freq[a] = 0;
    cout << sum << '\n';
  }
  return 0;
}
