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