#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int sum = 0;
  int A[100010] = {};
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    A[a]++;
  }
  int q;
  cin >> q;
  int s = sum;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    s = s + (c - b) * A[b];
    cout << s << endl;
    A[c] = A[c] + A[b];
    A[b] = 0;
  }
  return 0;
}
