#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
int mysum(map<int, int> &m, int &firstValue, int v, int r) {
  int oldV = (v * m[v]), oldR = 0;
  if (m.find(r) != m.end()) oldR = (m[r] * r);
  oldV += oldR;
  m[r] += m[v];
  m.erase(v);
  int newValue = (r * m[r]);
  firstValue -= oldV;
  firstValue += newValue;
  return firstValue;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> m{};
  for (int i = (0); i < (int)n; i++) {
    int x;
    cin >> x;
    m[x]++;
  }
  int q;
  cin >> q;
  int firstSum = 0;
  map<int, int>::iterator it;
  for (it = m.begin(); it != m.end(); it++) {
    firstSum += (it->first * it->second);
  }
  for (int i = (0); i < (int)q; i++) {
    int value, newValue;
    cin >> value >> newValue;
    cout << mysum(m, firstSum, value, newValue) << endl;
  }
  return 0;
}
