#include <bits/stdc++.h>
const int MOD = 1000000007;
const double PI = 3.14159265358979323846;
const int N = 100000;
using namespace std;
int a[N + 1];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    a[tmp]++;
    sum += tmp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    int x = c - b;
    sum += x * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
