#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<int, int> mii;
  int tmp;
  for (int i = 0; i < (N); ++i) {
    cin >> tmp;
    ++mii[tmp];
  }
  long long ans = 0;
  auto end = mii.end();
  for (auto itr = mii.begin(); itr != end; ++itr) {
    int f = itr->first;
    int s = itr->second;
    ans += f * (long long)s;
  }
  int Q;
  cin >> Q;
  int tmp1, tmp2;
  for (int i = 0; i < (Q); ++i) {
    cin >> tmp1 >> tmp2;
    ans += mii[tmp2] * tmp2 - mii[tmp1] * tmp1;
    mii[tmp2] += mii[tmp1];
    mii.erase(tmp1);
    cout << ans << "\n";
  }
  return 0;
}
