#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
map<int, int> num;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    num[x]++;
    sum += x;
  }
  int t;
  cin >> t;
  int b, c;
  while (t--) {
    cin >> b >> c;
    x = num[b];
    sum -= x * b;
    sum += x * c;
    num[b] = 0;
    num[c] += x;
    cout << sum << endl;
  }
  return 0;
}
