#include <bits/stdc++.h>
using namespace std;
void ayushmehta651() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  ayushmehta651();
  long long n;
  cin >> n;
  long long a[n];
  vector<long long> v;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    replace(v.begin(), v.end(), b, c);
    for (auto it3 : v) sum += it3;
    cout << sum << '\n';
  }
  return 0;
}
