#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  multiset<int> ms;
  ll ans = 0;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    ms.insert(a);
    ans += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    int cnt = ms.count(b);
    ms.erase(b);
    for (int i = 0; i < (cnt); ++i) ms.insert(c);
    ans += cnt * (c - b);
    cout << ans << endl;
  }
}
