#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int no;
    cin >> no;
    sum += no;
    mp[no]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum = sum - mp[b] * b - mp[c] * c;
    mp[c] += mp[b];
    mp[b] = 0;
    sum = sum + mp[b] * b + mp[c] * c;
    cout << sum << "\n";
  }
}
