#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
int digit(long long x) {
  if (x / 10 == 0) return 1;
  return digit(x / 10) + 1;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  return ((a * b == 0)) ? 0 : (a / gcd(a, b) * b);
}
double DegreeToRadian(double degree) { return degree * M_PI / 180.0; }
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int cnt[100010];
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cnt[a[i]]++;
  }
  cin >> q;
  vector<long long> ans(q + 1);
  ans[0] = sum;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    if (b == c || cnt[b] == 0) {
      ans[i] = ans[i - 1];
      continue;
    }
    sum = sum - (b * cnt[b]) + (c * cnt[b]);
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans[i] = sum;
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
