#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  multiset<int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    m.insert(temp);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int f, s;
    cin >> f >> s;
    int freq = m.count(f);
    int diff = s - f;
    sum = freq * diff + sum;
    for (int j = 0; j < freq; j++) {
      m.erase(f);
      m.insert(s);
    }
    cout << sum << endl;
  }
  return 0;
}
