#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
}
int main() {
  init();
  int n;
  cin >> n;
  int a;
  vector<int> A(100001, 0);
  int sum = 0;
  for (ll i = 0; i < (ll)(n); i++) {
    cin >> a;
    sum += a;
    A[a]++;
  }
  int q, b, c;
  cin >> q;
  vector<int> ans(q, 0);
  for (ll i = 0; i < (ll)(q); i++) {
    cin >> b >> c;
    if (A[b] != 0) {
      sum = sum + (A[b] * c - A[b] * b);
      A[c] += A[b];
      A[b] = 0;
    }
    ans[i] = sum;
  }
  for (ll i = 0; i < (ll)(q); i++) {
    cout << ans[i] << endl;
  }
}
