#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> nums(n);
  map<int, int> cnt;
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> nums[i];
    sum += nums[i];
    cnt[nums[i]]++;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    sum -= cnt[a] * a;
    sum += cnt[a] * b;
    cnt[b] += cnt[a];
    cnt.erase(a);
    cout << sum << '\n';
  }
}
