#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)(1e18) + 1;
vector<pair<int, int>> nums;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> nums;
  for (int i = 0; i < n; ++i) {
    int temp;
    cin >> temp;
    nums[temp]++;
  }
  long long ans = 0;
  for (auto num : nums) {
    ans += (num.first * num.second);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    ans += (c * nums[b]);
    ans -= (b * nums[b]);
    nums[c] += nums[b];
    nums[b] = 0;
    cout << ans << endl;
  }
  return 0;
}
