#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main() {
  int n, q;
  cin >> n;
  long long s = 0;
  map<int, int> A;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    A[a]++;
    s += a;
  }
  cin >> q;
  vector<pair<int, int>> BC;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    BC.emplace_back(b, c);
  }
  for (int i = 0; i < (int)(q); i++) {
    int b = BC[i].first;
    int c = BC[i].second;
    A[c] += A[b];
    s = s - b * A[b] + c * A[b];
    cout << s << endl;
    A[b] = 0;
  }
}
