#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
void Main() {
  int N;
  cin >> N;
  vector<int> cnt(100000);
  ll amount = 0;
  for (int i = 0; i < (N); ++i) {
    int a;
    cin >> a;
    amount += a;
    cnt[a - 1]++;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    int b, c;
    cin >> b >> c;
    amount -= b * cnt[b - 1];
    amount += c * (cnt[b - 1]);
    cnt[c - 1] += cnt[b - 1];
    cnt[b - 1] = 0;
    cout << amount << endl;
  }
}
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}
