#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  map<int, int> mp;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    mp[a] += 1;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    mp[c] = mp[c] + mp[b];
    mp[b] = 0;
    cout << sum << endl;
  }
}
