#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q, ans;
  cin >> n;
  ans = 0;
  int arr[100001] = {};
  for (long long i = 0; i < (n); ++i) {
    int s;
    cin >> s;
    ans += s;
    ++arr[s];
  }
  cin >> q;
  for (long long i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) * (arr[b]);
    arr[c] += arr[b];
    arr[b] = 0;
    cout << ans << "\n";
  }
}
