#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
vector<int> coun(1e5 + 1, 0);
vector<int> ans;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll total = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    total += a[i];
    coun[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    if (coun[b] == 0) {
      ans.push_back(total);
      continue;
    }
    total += (c - b) * coun[b];
    coun[c] += coun[b];
    coun[b] = 0;
    ans.push_back(total);
  }
  for (int i = 0; i < (ans.size()); ++i) cout << ans[i] << endl;
  return 0;
}
