#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll mod = 1000000007;
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() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  sort(a.begin(), a.end());
  for (int i = 0; i < q; i++) {
    int bi = b[i];
    int ci = c[i];
    std::replace(lower_bound(a.begin(), a.end(), bi),
                 upper_bound(a.begin(), a.end(), bi), bi, ci);
    cout << accumulate(a.begin(), a.end(), 0) << endl;
  }
}
