#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[100000] = {0};
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    sum += k;
    arr[k] += 1;
  }
  int q;
  cin >> q;
  long long arr1[q];
  for (int i = 0; i < q; i++) {
    int a;
    int b;
    cin >> a >> b;
    int t = arr[a];
    arr[b] += t;
    sum = sum + t * (b - a);
    arr1[i] = sum;
  }
  for (int i = 0; i < q; i++) {
    cout << arr1[i] << endl;
  }
}
