#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  long long total = 0;
  map<int, int> mp;
  for (auto x : a) mp[x]++;
  for (auto x : mp) total += x.first * x.second;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    total -= a * mp[a];
    total += mp[a] * b;
    mp[b] += mp[a];
    mp[a] = 0;
    cout << total << endl;
  }
  return 0;
}
