#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  map<int, int> l;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    sum += t;
    l[t] += 1;
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    int a = l[x];
    int b = l[y];
    l[y] += l[x];
    l[x] = 0;
    sum = sum - x * a - y * b + y * l[y];
    cout << sum << endl;
  }
}
