#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  long long sum = 0;
  unordered_map<int, long long> u;
  for (int i = 0; i < n; i++) cin >> arr[i], sum += arr[i], u[arr[i]]++;
  int q, b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int bsum = u[b] * b;
    int csum = u[b] * c;
    sum = sum - bsum + csum;
    u[c] += u[b];
    u[b] = 0;
    cout << sum << "\n";
  }
}
