#include <bits/stdc++.h>
using namespace std;
using namespace std;
const long long int M = 1e9 + 7;
long long int n, ans;
void solve() {
  int n;
  cin >> n;
  int arr[n];
  long long int s = 0;
  map<int, int> f;
  for (int i = 0; i < n; i++) cin >> arr[i], f[arr[i]]++, s = s + arr[i];
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    s = s - f[a] * a;
    s = s + f[a] * b;
    f[b] = f[b] + f[a];
    f[a] = 0;
    cout << s << endl;
  }
}
int main() {
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
