#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n, k, b, c;
  long long sum;
  cin >> n;
  int cnt[n];
  for (int i = 0; i < n; ++i) {
    cin >> cnt[i];
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    cin >> b >> c;
    sum = 0;
    for (int j = 0; j < n; ++j) {
      if (cnt[j] == b) {
        cnt[j] = c;
      }
      sum += cnt[j];
    }
    cout << sum << endl;
  }
}
