#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n, sum = 0;
  cin >> n;
  int a[n];
  std::vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    v.push_back(a[i]);
  }
  int t;
  cin >> t;
  int a1, b;
  while (t--) {
    int sum1 = 0;
    cin >> a1 >> b;
    int cnt = count(v.begin(), v.end(), a1);
    sum1 += ((sum - (cnt * a1)) + (cnt * b));
    cout << sum1 << endl;
    replace(v.begin(), v.end(), a1, b);
    sum = sum1;
  }
  return 0;
}
