#include <bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y) {
  int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int modpower(int x, unsigned int y, int p) {
  int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n;
    unordered_map<int, int> um;
    int a[n], sum = 0;
    for (int i = 0; i < n; i++) cin >> a[i], sum += a[i], um[a[i]]++;
    cin >> k;
    while (k--) {
      int x, y;
      cin >> x >> y;
      if (x < y) {
        int v = um[x];
        sum += (abs(x - y)) * v, cout << sum << '\n';
        um[x] = 0, um[y] += v;
      } else {
        int v = um[x];
        sum -= (abs(x - y)) * v, cout << sum << '\n';
        um[x] = 0, um[y] += v;
      }
    }
  }
  return 0;
}
