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