#include <bits/stdc++.h>
using namespace std;
void mpdump(map<int, int> mp) {
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cout << "key = " << itr->first << ", val = " << itr->second << "\n";
  }
}
unsigned long long mpsum(map<int, int> mp) {
  unsigned long long sum = 0;
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    sum += itr->first * itr->second;
  }
  return sum;
}
int main() {
  map<int, int> mp;
  int n, q, tmp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    mp[tmp] += 1;
  }
  scanf("%d", &q);
  int b, c;
  unsigned long long sum = mpsum(mp);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &b, &c);
    sum -= mp[b] * b;
    sum += mp[b] * c;
    mp[c] += mp[b];
    mp.erase(b);
    cout << sum << "\n";
  }
}
