#include <bits/stdc++.h>
const double PI = acos(-1);
using namespace std;
const long long MOD = long long(1e9 + 7);
const long long INF = long long(1e18) + 7;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
unsigned getDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
unsigned binarySearch(long long target, long long max, long long min) {
  while ((max - min) > 1) {
    if ((max + min) / 2 > target) {
      max = (max + min) / 2;
      min = min;
    } else {
      max = max;
      min = (max + min) / 2;
    }
  }
}
void f(int rest, string s) {
  char abc[] = "abc";
  if (rest == 0) {
    cout << s << endl;
  } else {
    for (int i = 0; i < 3; i++) {
      f(rest - 1, s + abc[i]);
    }
  }
}
struct UnionFind {
  vector<long long> par;
  map<long long, long long> s;
  UnionFind(long long n) : par(n) {
    for (long long i = 0; i < n; i++) {
      par[i] = i;
      s[i]++;
    }
  }
  long long root(long long x) {
    if (par[x] == x) return x;
    return root(par[x]);
  }
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) return;
    if (size(rx) > size(ry)) {
      s[rx] = s[rx] + s[ry];
      par[root(y)] = rx;
    } else {
      s[ry] = s[ry] + s[rx];
      par[root(x)] = ry;
    }
  }
  bool same(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return s[root(x)]; }
};
long long mod_pow(long long base, long long exp, long long mod) {
  if (exp == 1) return base % mod;
  if (exp % 2 == 1) return (base * mod_pow(base, exp - 1, mod)) % mod;
  long long t = mod_pow(base, exp / 2, mod);
  return (t * t) % mod;
}
long long mod_permutation(long long n, long long r) {
  long long t = 1;
  while (r != 0) {
    t = (t % MOD) * (n % MOD);
    n--;
    r--;
  }
  return t;
}
long long mod_factorial(long long r) {
  long long v = 1;
  while (r != 0) {
    v = (v % MOD) * (r % MOD);
    r--;
  }
  return v;
}
vector<long long> prime_factorization(long long n) {
  vector<long long> P;
  long long nn = sqrt(n) + 2;
  vector<long long> prime(nn + 1, true);
  for (long long i = 2; i <= nn; i++) {
    if (prime[i]) {
      for (long long j = 2 * i; j <= nn; j += i) {
        prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  vector<long long> d;
  for (long long i = 0; i < P.size(); i++) {
    while (n % P[i] == 0) {
      d.push_back(P[i]);
      n /= P[i];
    }
  }
  if (n > nn) d.push_back(n);
  return d;
}
vector<long long> sieve(long long n) {
  vector<long long> P;
  long long nn = sqrt(n) + 2;
  vector<long long> prime(nn + 1, true);
  for (long long i = 2; i <= nn; i++) {
    if (prime[i]) {
      for (long long j = 2 * i; j <= nn; j += i) {
        prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}
bool is_prime(long long n) {
  long long nn = sqrt(n) + 2;
  vector<long long> prime(nn + 1, true);
  if (n % 2 == 0) {
    return false;
  }
  vector<long long> primes = sieve(nn);
  for (long long i = 0; i < primes.size(); i++) {
    if (n % primes[i] == 0) {
      return false;
    }
  }
  return true;
}
struct Node {
  vector<long long> edges;
  vector<long long> costs;
  bool done;
  long long cost;
  friend bool operator<(const Node& lhs, const Node& rhs) {
    return rhs.cost < lhs.cost;
  }
};
long long mod_conb(long long n, long long r, long long mod) {
  return (mod_factorial(n) / mod_factorial(n - r) / mod_factorial(r)) % mod;
}
vector<vector<long long>> vv;
long long c = 0;
vector<long long> v;
long long n, m, q;
void dfs2(long long index, long long count) {
  if (count < n) {
    for (long long i = index; i <= m; i++) {
      v[count] = i;
      dfs2(i, count + 1);
    }
  } else {
    vv.push_back(v);
  }
}
long long total(vector<long long> v) {
  long long t = 0;
  for (long long i = 0; i < v.size(); i++) {
    t += v[i];
  }
  return t;
}
int main() {
  long long n, q;
  cin >> n;
  vector<long long> a(n);
  map<long long, long long> m;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  vector<long long> dp;
  dp.push_back(sum);
  cin >> q;
  vector<long long> b(q);
  vector<long long> c(q);
  for (long long i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
    dp[i + 1] = dp[i] + (m[b[i]] * (c[i] - b[i]));
    m[c[i]] += m[b[i]];
    m[b[i]] = 0;
  }
  for (long long i = 1; i < q + 1; i++) {
    cout << dp[i] << endl;
  }
  return 0;
}
