#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int arr[100001] = {0};
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
    arr[x]++;
  }
  int q;
  long long int sum = accumulate(v.begin(), v.end(), 0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    long long int diff = b - a;
    sum = sum + (arr[a]) * diff;
    arr[b] = arr[b] + arr[a];
    arr[a] = 0;
    cout << sum << endl;
  }
}
