#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y, ind;
  char ch;
};
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long fact[13];
void factorial() {
  fact[0] = 1;
  for (long long i = 1; i < 12; i++) fact[i] = (fact[i - 1] * i);
}
bool cmp(point A, point B) {
  if (A.x != B.x) return A.x < B.x;
  return A.y < B.y;
}
const long long mx = 200007;
long long n, a, b, _, ans, c, _1, _2, m, an, k, dif_num, mxtm;
vector<long long> gd_num;
bool ok;
string st;
long long ar[mx], cou[mx], res[mx];
map<long long, long long> mm;
char ch;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << setprecision(12);
  cin >> n;
  ans = 0;
  for (long long i = 0; i < n; i++) {
    cin >> ar[i];
    ans += ar[i];
    cou[ar[i]]++;
  }
  cin >> k;
  for (long long i = 0; i < k; i++) {
    cin >> _1 >> _2;
    _ = cou[_1];
    cou[_2] += _;
    ans += (_2 - _1) * _;
    cout << ans << "\n";
  }
  return 0;
}
