#include <stdio.h>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cassert>
struct SegmentTree {
int size;
std::vector<int> data;
void build(int v, int l, int r, const std::vector<bool>& array) {
if (l == r) {
data[v] = array[l];
} else {
int m = (l + r) / 2;
build(2*v+1, l, m, array);
build(2*v+2, m+1, r, array);
data[v] = data[2*v+1] + data[2*v+2];
}
}
void set(int v, int l, int r, int p, int a) {
if (l == r) {
data[v] = a;
} else {
int m = (l + r) / 2;
if (p <= m) {
set(2*v+1, l, m, p, a);
} else {
set(2*v+2, m+1, r, p, a);
}
data[v] = data[2*v+1] + data[2*v+2];
}
}
void set(int pos, int value) {
set(0, 0, size-1, pos, value);
}
int get(int sum) const {
// Найти самый левый r, такой что сумма на отрезке [0, r] равна sum.
int v = 0, l = 0, r = size-1;
while (l < r) {
if (data[2*v+1] >= sum) {
v = 2*v+1;
r = (l+r) / 2;
} else {
sum -= data[2*v+1];
v = 2*v+2;
l = (l+r) / 2 + 1;
}
}
return r;
}
SegmentTree(const std::vector<bool>& array) {
size = (int)array.size();
int pow = 1;
while (pow < size) pow *= 2;
assert(pow >= size);
data.resize(2*pow);
build(0, 0, size-1, array);
}
};
int main() {
double t = clock();
int n, k, q;
scanf("%d %d %d", &n, &k, &q);
std::vector<int> answer(1+n, 0);
SegmentTree st(std::vector<bool>(1+n,true));
st.set(0,0);
while (n >= k) {
int sum = k, erased = 0, limit = n / k;
while (erased < limit) {
int number = st.get(sum);
st.set(number, 0);
answer[number] = (int)answer.size() - n + erased;
sum += k - 1;
++erased;
}
n -= erased;
}
while (q--) {
int item;
scanf("%d", &item);
printf("%d\n", answer[item]);
}
fprintf(stderr, "time = %0.3fs\n", (clock() - t) / CLOCKS_PER_SEC);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8Y3RpbWU+CiNpbmNsdWRlIDxjYXNzZXJ0PgoKc3RydWN0IFNlZ21lbnRUcmVlIHsKICAgIAogICAgaW50IHNpemU7CiAgICAKICAgIHN0ZDo6dmVjdG9yPGludD4gZGF0YTsKICAgIAogICAgdm9pZCBidWlsZChpbnQgdiwgaW50IGwsIGludCByLCBjb25zdCBzdGQ6OnZlY3Rvcjxib29sPiYgYXJyYXkpIHsKICAgICAgICBpZiAobCA9PSByKSB7CiAgICAgICAgICAgIGRhdGFbdl0gPSBhcnJheVtsXTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBpbnQgbSA9IChsICsgcikgLyAyOwogICAgICAgICAgICBidWlsZCgyKnYrMSwgICBsLCBtLCBhcnJheSk7CiAgICAgICAgICAgIGJ1aWxkKDIqdisyLCBtKzEsIHIsIGFycmF5KTsKICAgICAgICAgICAgZGF0YVt2XSA9IGRhdGFbMip2KzFdICsgZGF0YVsyKnYrMl07CiAgICAgICAgfQogICAgfQogICAgCiAgICB2b2lkIHNldChpbnQgdiwgaW50IGwsIGludCByLCBpbnQgcCwgaW50IGEpIHsKICAgICAgICBpZiAobCA9PSByKSB7CiAgICAgICAgICAgIGRhdGFbdl0gPSBhOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGludCBtID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIGlmIChwIDw9IG0pIHsKICAgICAgICAgICAgICAgIHNldCgyKnYrMSwgICBsLCBtLCBwLCBhKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHNldCgyKnYrMiwgbSsxLCByLCBwLCBhKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkYXRhW3ZdID0gZGF0YVsyKnYrMV0gKyBkYXRhWzIqdisyXTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIHZvaWQgc2V0KGludCBwb3MsIGludCB2YWx1ZSkgewogICAgICAgIHNldCgwLCAwLCBzaXplLTEsIHBvcywgdmFsdWUpOwogICAgfQogICAgCiAgICBpbnQgZ2V0KGludCBzdW0pIGNvbnN0IHsKICAgICAgICAvLyDQndCw0LnRgtC4INGB0LDQvNGL0Lkg0LvQtdCy0YvQuSByLCDRgtCw0LrQvtC5INGH0YLQviDRgdGD0LzQvNCwINC90LAg0L7RgtGA0LXQt9C60LUgWzAsIHJdINGA0LDQstC90LAgc3VtLgogICAgICAgIGludCB2ID0gMCwgbCA9IDAsIHIgPSBzaXplLTE7CiAgICAgICAgd2hpbGUgKGwgPCByKSB7CiAgICAgICAgICAgIGlmIChkYXRhWzIqdisxXSA+PSBzdW0pIHsKICAgICAgICAgICAgICAgIHYgPSAyKnYrMTsKICAgICAgICAgICAgICAgIHIgPSAobCtyKSAvIDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzdW0gLT0gZGF0YVsyKnYrMV07CiAgICAgICAgICAgICAgICB2ID0gMip2KzI7CiAgICAgICAgICAgICAgICBsID0gKGwrcikgLyAyICsgMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gcjsKICAgIH0KICAgIAogICAgU2VnbWVudFRyZWUoY29uc3Qgc3RkOjp2ZWN0b3I8Ym9vbD4mIGFycmF5KSB7CiAgICAgICAgc2l6ZSA9IChpbnQpYXJyYXkuc2l6ZSgpOwogICAgICAgIGludCBwb3cgPSAxOwogICAgICAgIHdoaWxlIChwb3cgPCBzaXplKSBwb3cgKj0gMjsKICAgICAgICBhc3NlcnQocG93ID49IHNpemUpOwogICAgICAgIGRhdGEucmVzaXplKDIqcG93KTsKICAgICAgICBidWlsZCgwLCAwLCBzaXplLTEsIGFycmF5KTsKICAgIH0KfTsKCmludCBtYWluKCkgewogICAgZG91YmxlIHQgPSBjbG9jaygpOwogICAgCiAgICBpbnQgbiwgaywgcTsKICAgIHNjYW5mKCIlZCAlZCAlZCIsICZuLCAmaywgJnEpOwogICAgCiAgICBzdGQ6OnZlY3RvcjxpbnQ+IGFuc3dlcigxK24sIDApOwogICAgCiAgICBTZWdtZW50VHJlZSBzdChzdGQ6OnZlY3Rvcjxib29sPigxK24sdHJ1ZSkpOwogICAgCiAgICBzdC5zZXQoMCwwKTsKICAgIAogICAgd2hpbGUgKG4gPj0gaykgewogICAgICAgIGludCBzdW0gPSBrLCBlcmFzZWQgPSAwLCBsaW1pdCA9IG4gLyBrOwogICAgICAgIHdoaWxlIChlcmFzZWQgPCBsaW1pdCkgewogICAgICAgICAgICBpbnQgbnVtYmVyID0gc3QuZ2V0KHN1bSk7CiAgICAgICAgICAgIHN0LnNldChudW1iZXIsIDApOwogICAgICAgICAgICBhbnN3ZXJbbnVtYmVyXSA9IChpbnQpYW5zd2VyLnNpemUoKSAtIG4gKyBlcmFzZWQ7CiAgICAgICAgICAgIHN1bSArPSBrIC0gMTsKICAgICAgICAgICAgKytlcmFzZWQ7CiAgICAgICAgfQogICAgICAgIG4gLT0gZXJhc2VkOwogICAgfQogICAgCiAgICB3aGlsZSAocS0tKSB7CiAgICAgICAgaW50IGl0ZW07CiAgICAgICAgc2NhbmYoIiVkIiwgJml0ZW0pOwogICAgICAgIHByaW50ZigiJWRcbiIsIGFuc3dlcltpdGVtXSk7CiAgICB9CiAgICBmcHJpbnRmKHN0ZGVyciwgInRpbWUgPSAlMC4zZnNcbiIsIChjbG9jaygpIC0gdCkgLyBDTE9DS1NfUEVSX1NFQyk7CiAgICByZXR1cm4gMDsKfQ==