#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  ll a[100001 + 1];
  for (int i = 1; i <= 100001; i++) {
    a[i] = 0;
  };
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  ll sum = 0;
  for (int j = 1; j <= n; j++) {
    sum += j * a[j];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;
    if (b != c) {
      sum -= b * a[b];
      sum -= c * a[c];
      a[c] += a[b];
      a[b] = 0;
      sum += c * a[c];
    }
    cout << sum << endl;
  }
}
