#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[100001] = {0};
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
    sum += a[i];
  }
  int m;
  cin >> m;
  while (m--) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    ans = sum;
    ans -= b[p] * p;
    ans += q * b[p];
    b[q] += b[p];
    b[p] = 0;
    sum = ans;
    cout << ans << "\n";
  }
  return 0;
}
