#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> arr(n);
  int sum = 0;
  unordered_map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    mp[arr[i]]++;
  }
  int q;
  cin >> q;
  vector<int> res;
  for (int i = 0; i < q; i++) {
    int a;
    int b;
    cin >> a >> b;
    int x = mp[a];
    sum = sum - a * x;
    sum = sum + b * x;
    res.push_back(sum);
    mp[b] = mp[b] + x;
    mp.erase(a);
  }
  for (int i = 0; i < res.size(); i++) {
    cout << res[i] << endl;
  }
  return 0;
}
