#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (long long r = a % b) a = b, b = r;
  return b;
}
class mod {
 public:
  long long val;
  mod(long long v) { val = v % 1000000007; }
  mod() { val = 0; }
  void operator-=(const mod &v) {
    val -= v.val;
    if (val < 0) val += 1000000007;
  }
  void operator+=(const mod &v) {
    if (val + v.val >= 1000000007) val -= 1000000007;
    val += v.val;
  }
  void operator+=(long long &v) {
    if (val + v >= 1000000007) val -= 1000000007;
    val += v;
  }
  void operator*=(const mod &v) {
    val *= v.val;
    val %= 1000000007;
  }
  void operator*=(long long &v) {
    val *= v;
    val %= 1000000007;
  }
  long long modinv(long long a) {
    long long b = 1000000007, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= 1000000007;
    if (u < 0) u += 1000000007;
    return u;
  }
  void operator/=(const mod &v) {
    val *= modinv(v.val);
    val %= 1000000007;
  }
  void operator/=(long long &v) {
    val *= modinv(v);
    val %= 1000000007;
  }
};
struct UnionFind {
  vector<int> par;
  vector<int> childN;
  long long r = 0;
  UnionFind(int N) : par(N), childN(N) {
    for (int i = 0; i < N; i++) par[i] = i, childN[i] = 1;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    r -= childN[rx] * (childN[rx] - 1) / 2;
    r -= childN[ry] * (childN[ry] - 1) / 2;
    childN[ry] += childN[rx];
    childN[rx] = 0;
    r += childN[ry] * (childN[ry] - 1) / 2;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };
using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) {
  return a.second > b.second || (a.second == b.second && a.first > b.first);
};
bool operator<(const xpair &a, const xpair &b) {
  return a.second < b.second || (a.second == b.second && a.first > b.first);
};
bool operator==(const xpair &a, const xpair &b) { return a.first == b.first; };
int main() {
  int n, q;
  cin >> n;
  map<int, int> a;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    if (a.find(in) == a.end())
      a[in] = 1;
    else
      a[in]++;
    sum += in;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    auto itr = a.find(b);
    if (itr != a.end()) {
      int num = itr->second;
      sum += (c - b) * num;
      if (a.find(c) != a.end())
        a[c] += num;
      else
        a[c] = num;
      a.erase(itr);
    }
    printf("%lld", sum);
  }
  return 0;
}
