#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
  return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
  return a * a;
}
template <class T>
T gcd(T a, T b) {
  return a ? gcd(b % a, a) : b;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sign(T a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
void fastIO() {
  cin.sync_with_stdio(false);
  cin.tie(0);
}
template <typename T>
vector<T> make_unique(vector<T> v) {
  sort((v).begin(), (v).end());
  return v.resize(unique((v).begin(), (v).end()) - v.begin());
}
int nxt() {
  int x;
  cin >> x;
  return x;
}
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
const int dyKn[8] = {1, 2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const long long INF64 = 2e18;
const long double PI = long double(3.1415926535897932384626433832795);
const long double e = long double(2.7182818284590452353602874713527);
const long double EPS = 1e-9;
const int MAXN = 100005;
int main() {
  fastIO();
  int frq[MAXN];
  long long ans = 0;
  int n = nxt();
  vector<int> v(n, 0);
  generate((v).begin(), (v).end(), nxt);
  memset(frq, 0, sizeof(frq));
  for (int i = 0; i < (int)(n); ++i) frq[v[i]]++, ans += v[i];
  int q = nxt();
  for (int i = 0; i < (int)(q); ++i) {
    int b, c;
    cin >> b >> c;
    if (frq[b] > 0) {
      ans -= (frq[b] * b);
      ans += (frq[b] * c);
      frq[c] += frq[b];
      frq[b] = 0;
    }
    cout << ans << "\n";
  }
  return 0;
}
