#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void ash() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ash();
  int n;
  cin >> n;
  vector<int> a;
  map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.emplace_back(x);
    m[x]++;
    sum = sum + x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    map<int, int>::iterator it = m.begin();
    while (it->first != x) {
      it++;
      if (it == m.end()) break;
    }
    if (it != m.end()) {
      sum = sum - (x * (it->second)) + ((it->second) * y);
      cout << sum << "\n";
      int q = it->second;
      m.erase(it);
      m.insert({y, q});
    } else {
      cout << sum << "\n";
    }
  }
}
