#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
long long comb(long long a, long long b) {
  long long x = max(a - b, b), ans = 1;
  for (long long K = a, L = 1; K >= x + 1; K--, L++) {
    ans *= K;
    ans /= L;
  }
  return ans;
}
void task() {
  long long n, q, a, b, sum = 0;
  cin >> n;
  int ara[n];
  vector<int> mark(100001);
  for (int K = 0; K < n; K++) {
    cin >> ara[K];
    sum += ara[K];
    mark[ara[K]]++;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    mark[b] += mark[a];
    sum = sum - mark[a] * a + mark[a] * b;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  task();
  return 0;
}
