#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int a[MAX];
int freq[MAX];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      freq[a[i]]++;
      sum += a[i];
    }
    int q;
    cin >> q;
    long long woo[q + 1];
    long long ans = sum;
    for (int i = 1; i <= q; i++) {
      int b, c;
      cin >> b >> c;
      int ct = freq[b];
      ans -= (ct * b);
      freq[b] = 0;
      ans += (ct * c);
      freq[c] += ct;
      woo[i] = ans;
      sum = ans;
    }
    for (int i = 1; i <= q; i++) cout << woo[i] << "\n";
  }
  return 0;
}
