#include <bits/stdc++.h>
using namespace std;
long long int smallestDivisor(long long int n) {
  if (n % 2 == 0) return 2;
  for (long long int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return i;
  }
  return n;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / (gcd(a, b));
}
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
int cnt[200005] = {0};
vector<int> adj[200005];
void factorize(int n) {
  int count = 0;
  map<int, int> fact;
  while (!(n % 2)) {
    n /= 2;
    count++;
  }
  if (count) fact[2] += count;
  for (int i = 3; i <= sqrt(n); i += 2) {
    count = 0;
    while ((n % i) == 0) {
      count++;
      n /= i;
    }
    if (count) fact[i] += count;
  }
  if (n > 2) fact[n]++;
}
long long int power(long long int x, int p) {
  if (p == 0) return 1;
  long long int ans = power(x, p / 2);
  ans = ans * ans;
  if (p % 2 == 1) ans = ans * x;
  return ans;
}
long long int factorial(long long int n) {
  if (n <= 1) return 1;
  long long int ans = 1;
  for (long long int i = 1; i <= n; i++) {
    ans = ans * i;
  }
  return ans;
}
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
vector<long long int> countDivisors(long long int n) {
  long long int cnt = 0;
  std::vector<long long int> v;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (n / i == i)
        cnt++;
      else {
        cnt = cnt + 2;
        v.push_back(n / i);
      }
    }
  }
  return v;
}
long long int highestPowerof2(long long int n) {
  long long int p = (long long int)log2(n);
  return (long long int)pow(2, p);
}
bool isPowerOfTwo(long long int x) { return (x && !(x & (x - 1))); }
map<long long int, long long int> factors(long long int n) {
  vector<long long int> f;
  map<long long int, long long int> m;
  for (long long int x = 2; x * x <= n; x++) {
    while (n % x == 0) {
      f.push_back(x);
      m[x]++;
      n /= x;
    }
  }
  if (n > 1) {
    f.push_back(n);
    m[n]++;
  }
  return m;
}
long long int binarySearch(long long int arr[], long long int l,
                           long long int r, long long int x) {
  if (r >= l) {
    long long int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x);
    return binarySearch(arr, mid + 1, r, x);
  }
  return -1;
}
int rub[2000001];
bool ispali(int n) {
  int no = n;
  int rev = 0;
  while (no > 0) {
    int ld = no % 10;
    no /= 10;
    rev = rev * 10 + ld;
  }
  if (n == rev)
    return true;
  else
    return false;
}
void np() {
  for (int i = 1; i <= 2000000; i++) {
    if (ispali(i))
      rub[i] = rub[i - 1] + 1;
    else
      rub[i] = rub[i - 1];
  }
}
int pi[20000001];
bool isprime[20000001];
void seive() {
  for (int i = 4; i <= 20000000; i += 2) isprime[i] = 1;
  for (int i = 3; i * i <= 20000000; i += 2) {
    if (!isprime[i]) {
      for (int j = i * i; j <= 20000000; j += i) isprime[j] = 1;
    }
  }
  for (int i = 2; i <= 20000000; i++) {
    if (!isprime[i])
      pi[i] = pi[i - 1] + 1;
    else
      pi[i] = pi[i - 1];
  }
}
int g1;
void bfs(vector<vector<int> > &g, int pos, vector<int> visited) {
  queue<int> q;
  q.push(pos);
  while (q.size() > 0) {
    if (q.front() == g1) {
      cout << "yes";
      return;
    }
    int i = q.front();
    q.pop();
    visited[i] = 1;
    for (int j = 0; j < g[i].size(); j++) {
      if (visited[g[i][j]] == 0) {
        q.push(g[i][j]);
        visited[g[i][j]] = 1;
      }
    }
  }
  return;
}
void pairsort(long long int a[], long long int b[], long long int n) {
  pair<long long int, long long int> pairt[n];
  for (long long int i = 0; i < n; i++) {
    pairt[i].first = a[i];
    pairt[i].second = b[i];
  }
  sort(pairt, pairt + n);
  for (long long int i = 0; i < n; i++) {
    a[i] = pairt[i].first;
    b[i] = pairt[i].second;
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    int b[100001] = {0};
    int a[n];
    long long int s = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
      s += a[i];
      b[a[i]]++;
    }
    int q;
    cin >> q;
    while (q--) {
      int b1, c1;
      cin >> b1 >> c1;
      if (b[b1] > 0) {
        int te = b[b1];
        b[b1] = 0;
        if (b[c1]) s -= c1 * b[c1];
        b[c1] += te;
        s -= b1 * te;
        s += c1 * b[c1];
      }
      cout << s << "\n";
    }
  }
  return 0;
}
