#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& v : a) cin >> v;
  unordered_map<int, int> table;
  ll sum = 0;
  for (auto v : a) {
    sum += v;
    table[v]++;
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    int x = table[b];
    sum -= x * b;
    sum += x * c;
    cout << sum << '\n';
    table.erase(b);
    table[c] += x;
  }
}
