#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, sum = 0;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
  }
  sort((v).begin(), (v).end());
  int k;
  cin >> k;
  vector<pair<int, int> > p(k);
  for (int i = 0; i < k; ++i) {
    int x, y;
    cin >> x >> y;
    int lsum = 0;
    for (int i = 0; i < n; ++i) {
      if (v[i] == x) v[i] = y;
      lsum += v[i];
    }
    cout << lsum << '\n';
  }
}
