#include <bits/stdc++.h>
using namespace std;
long long sum = 0;
int _count;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a.at(i);
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) {
    cin >> b.at(i) >> c.at(i);
    _count = count(a.begin(), a.end(), b.at(i));
    a.erase(remove(a.begin(), a.end(), b.at(i)), a.end());
    for (int j = 0; j < (int)(_count); j++) a.push_back(c.at(i));
    sum = 0;
    for (int i = 0; i < (int)(n); i++) sum += a.at(i);
    cout << sum << endl;
  }
  return 0;
}
