#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int main() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long res;
  for (int i = 0; i < (n); ++i) {
    long long a;
    cin >> a;
    mp[a]++;
    res += a;
  }
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    long long num = mp[b];
    mp[b] = 0;
    mp[c] += num;
    res += (c - b) * num;
    cout << res << endl;
  }
  return 0;
}
