#include <array>
#include <iostream>
#include <map>
#include <vector>

inline constexpr std::size_t MaxValue = 100'000;

int
main()
{
    std::ios::sync_with_stdio(false);

    std::size_t valueCount;
    std::cin >> valueCount;

    std::vector<int> values(valueCount);

    for (std::size_t i = 0; i<valueCount; ++i)
    {
        std::cin >> values[i];
    }

    std::size_t operationCount;
    std::cin >> operationCount;

    std::vector<int> oldValues(operationCount);
    std::vector<int> newValues(operationCount);

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        std::cin >> oldValues[i];
        std::cin >> newValues[i];
    }

    long long sum = 0;
    std::vector<int> valueCounts(MaxValue+1, 0);
    for (auto &value : values)
    {
        valueCounts[value] = 1;
        sum += value;
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto oldValue = oldValues[i];
        auto newValue = newValues[i];

        auto count = valueCounts[oldValue];
        if (count==0)
        {
            std::cout << sum << "\n";
            continue;
        }

        sum -= static_cast<long long>(oldValue)*count;
        sum += static_cast<long long>(newValue)*count;
        valueCounts[oldValue] = 0;
        valueCounts[newValue] += count;

        std::cout << sum << "\n";
    }
}
