#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 2147483647;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  ll sum = 0;
  for (int i = 0; i < int(n); ++i) {
    int input;
    cin >> input;
    sum += input;
    mp[input]++;
  }
  int q;
  cin >> q;
  vector<ll> ans;
  for (int i = 0; i < int(q); ++i) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    ans.push_back(sum);
  }
  for (int i = 0; i < int(ans.size()); ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}
