#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, q;
  cin >> n;
  int a[100010];
  int fr[100010];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    fr[a[i]]++;
  }
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum -= fr[b] * b;
    sum += fr[b] * c;
    fr[c] += fr[b];
    fr[b] = 0;
    cout << sum << '\n';
  }
}
