#include <bits/stdc++.h>
const int M = 1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a;
  for (long long int i = 0; i < n; i++) {
    long long int o;
    cin >> o;
    a.push_back(o);
  }
  long long int z = 0;
  sort(a.begin(), a.end());
  long long int t;
  cin >> t;
  while (t--) {
    long long int x, y;
    cin >> x >> y;
    for (long long int i = 0; i < n; i++) {
      if (a[i] == x) {
        a[i] = y;
      }
    }
    cout << accumulate(a.begin(), a.end(), z) << "\n";
  }
  return 0;
}
