#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i <= n - 1; i += 1) {
    cin >> arr[i];
    sum += arr[i];
    mp[arr[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= (b * mp[b]);
    sum += (c * mp[b]);
    mp[c] += mp[b];
    mp[b] = 0;
    cout << sum << "\n";
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
}
