#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 3;
long long m[N] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n, q, n1, n2, sum, val;
  cin >> n;
  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> val;
    sum = sum + val;
    m[val]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> n1 >> n2;
    sum = sum + (n2 - n1) * m[n1];
    cout << sum << '\n';
    m[n2] = m[n2] + m[n1];
    m[n1] = 0;
  }
  return 0;
}
