#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  int p[100005] = {0};
  for (int i = 0; i < n; i++) p[a[i]]++;
  ll sum = 0;
  for (int i = 0; i < 100005; i++) sum += i * p[i];
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum - p[b] * b + p[b] * c;
    p[c] = p[b] + p[c];
    p[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
