#include <bits/stdc++.h>
using namespace std;
void power(int a, int n) {
  unsigned long long ans = 1;
  while (n > 0) {
    if (n % 2) {
      ans *= a;
      n--;
      cout << ans << "\n";
    } else {
      a *= a;
      n /= 2;
    }
  }
  cout << ans << "\n";
}
void solve() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sort(ar, ar + n);
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      if (ar[i] == a) ar[i] = b;
      sum += ar[i];
    }
    cout << sum << "\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
