#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    A.push_back(x);
  }
  unordered_map<int, int> F;
  for (int a : A) {
    F[a] += 1;
  }
  int q;
  cin >> q;
  int currsum = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    currsum -= F[b] * b;
    currsum += F[b] * c;
    F[c] += F[b];
    F[b] = 0;
    cout << currsum << "\n";
  }
}
