#include <bits/stdc++.h>
using namespace std;
int binarySearch(int arr[], int p, int r, int num) {
  if (p <= r) {
    int mid = (p + r) / 2;
    if (arr[mid] == num) return mid;
    if (arr[mid] > num) return binarySearch(arr, p, mid - 1, num);
    if (arr[mid] > num) return binarySearch(arr, mid + 1, r, num);
  }
  return -1;
}
int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long sum = 0;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    m[a[i]]++;
  }
  map<long long, long long>::iterator it;
  int q, b, c;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    cin >> b >> c;
    if (m[b] != 0) {
      for (it = m.begin(); it != m.end(); it++) {
        if (it->first == b) {
          sum = sum - (b * it->second) + (c * it->second);
          m[c] = m[c] + it->second;
          break;
        }
      }
    }
    cout << sum << endl;
  }
  return 0;
}
