#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vec a(n);
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  int q;
  cin >> q;
  sort(a.begin(), a.end());
  vec ans(100005, 0);
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < (int)(n); j++) {
      if (a[j] == b) a[j] = c;
      if (a[j + 1] > b) break;
    }
    for (int k = 0; k < (int)(n); k++) ans[i] += a[k];
  }
  for (int i = 0; i < (int)(q); i++) cout << ans[i] << endl;
}
