#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n) {
  if (n == 0 || n == 1) return 1;
  long long res = 1;
  for (long long i = 2; i <= n; i++) res = (res * n) % 1000000007;
  return res;
}
long long mpow(long long a, long long n) {
  long long ret = 1;
  long long b = a;
  while (n) {
    if (n & 1) {
      ret = (ret * b) % 1000000007;
    }
    b = (b * b) % 1000000007;
    n >>= 1;
  }
  return (long long)ret;
}
int toint(const string &s) {
  stringstream ss(s);
  int x;
  ss >> x;
  return x;
}
long long xGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1, gcd = xGCD(b, a % b, x1, y1);
  x = y1;
  y = x1 - (a / b) * y1;
  return gcd;
}
long long inverse(long long a) {
  long long x, y;
  long long gcd = xGCD(a, 1000000007, x, y);
  return (x % 1000000007 + 1000000007) % 1000000007;
}
long long bc(long long n, long long k) {
  if (n == k || k == 0) return 1;
  if (k == 1 || k == n - 1) return n;
  long long a = factorial(n);
  long long b = inverse(factorial(k));
  long long c = inverse(factorial(n - k));
  return ((a % 1000000007 * b % 1000000007) * c % 1000000007) % 1000000007;
}
void fastscan(long long &x) {
  bool neg = false;
  register int c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
int main() {
  const int N = 1e5 + 1;
  int m[N] = {0};
  int n;
  cin >> n;
  vector<long long> v(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int b1 = m[b];
    sum -= b1 * b;
    sum += b1 * c;
    m[c] += b1;
    m[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
