#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  multiset<int> A;
  cin >> N;
  long long sum = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A.insert(a);
    sum += a;
  }
  vector<int> L(100000, -1);
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    int B, C;
    cin >> B >> C;
    if (L[B - 1] == -1) {
      L[B - 1] = A.erase(B);
    }
    L[C - 1] = L[B - 1];
    L[B - 1] = 0;
    sum = sum + L[C - 1] * (C - B);
    cout << sum << endl;
  }
  return 0;
}
