#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
const int MAX = 10000007;
inline long long read() {
  char c = getchar();
  long long x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0', c = getchar();
  }
  return x * f;
}
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
int q[N];
map<int, int> mp, vis;
string s = "abcdefghijklmnopqrstuvwxyz";
int main() {
  int n;
  n = read();
  long long sum = 0;
  for (int i = (1); i <= (n); ++i) {
    q[i] = read();
    mp[q[i]]++;
    sum += q[i];
  }
  int m;
  m = read();
  int l, r;
  for (int i = (1); i <= (m); ++i) {
    scanf("%d%d", &l, &r);
    sum -= mp[l] * l;
    mp[r] += mp[l];
    sum += mp[l] * r;
    cout << sum << endl;
    mp[l] = 0;
  }
}
