#include <bits/stdc++.h>
using namespace std;
struct expand_type {
  template <typename... T>
  expand_type(T&&...) {}
};
template <typename... ArgTypes>
void print(ArgTypes... args) {
  expand_type{0, (cerr << args << ", ", 0)...};
  cerr << "\b\b \n";
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  map<int, int> nums;
  unsigned long long s = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    nums[num]++;
    s += num;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int cnt = nums[a];
    s -= a * cnt;
    s += b * cnt;
    nums[b] += cnt;
    nums.erase(a);
    cout << s << endl;
  }
  return 0;
}
