#include <bits/stdc++.h>
using namespace std;
void swap(int &a, int &b) {
  int t = a;
  a = b;
  b = t;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t, n, m;
  cin >> n;
  vector<unsigned long long> v(n);
  unordered_map<unsigned long long, unsigned long long> mp;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  cin >> m;
  unsigned long long sum = accumulate(v.begin(), v.end(), 0);
  for (int i = 0; i < m; i++) {
    unsigned long long a, b;
    cin >> a >> b;
    mp[b] += mp[a];
    sum += b * (mp[a]);
    sum -= a * mp[a];
    mp[a] = 0;
    cout << sum << "\n";
  }
  return 0;
}
