#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> A(100001, 0);
  ll sum = 0;
  for (int i = 0; i < (N); i++) {
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < (Q); i++) {
    int b, c;
    cin >> b >> c;
    sum -= b * A[b];
    sum += c * A[b];
    A[c] += A[b];
    A[b] = 0;
    cout << sum << endl;
  }
}
