#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  const int MAX = 1000;
  vector<int> cnt(MAX, 0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int(i) = 0; (i) < (n); ++(i)) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort((a).begin(), (a).end());
  ll s = accumulate((a).begin(), (a).end(), 0ll);
  int q;
  cin >> q;
  vector<pair<int, int>> bc;
  for (int(i) = 0; (i) < (q); ++(i)) {
    int b, c;
    cin >> b >> c;
    bc.push_back({b, c});
  }
  for (int(i) = 0; (i) < (q); ++(i)) {
    int before = bc[i].first;
    int after = bc[i].second;
    int sa = after - before;
    int c = cnt[before];
    s += (c * sa);
    cout << s << endl;
    cnt[before] = 0;
    cnt[after] += c;
  }
}
