local ffi = require("ffi") local C = ffi.C ffi.cdef[[ long long atoll(const char*); ]] local function lltonumber(str) return C.atoll(str) end local mfl = math.floor local function comp(a, b) return a < b end local function lower_bound(ary, x) local num = #ary if num == 0 then return 1 end if not comp(ary[1], x) then return 1 end if comp(ary[num], x) then return num + 1 end local min, max = 1, num while 1 < max - min do local mid = mfl((min + max) / 2) if comp(ary[mid], x) then min = mid else max = mid end end return max end local k, q = io.read("*n", "*n", "*l") k = 1LL * k local lim = 1000000007LL * 1000000007LL local function solve(x) local min, max = x - 1LL, x * 2LL + 10 while 1LL < max - min do local mid = (min + max) / 2LL local v = (mid + k - 1LL) / k if x + 1LL <= mid - v then max = mid else min = mid end end return max - 1LL end local t = {} local sz = 1LL while sz < lim do sz = solve(sz) table.insert(t, sz) end -- for i = 1, #t do -- print(i, t[i], ret[i]) -- end -- print(t[1]) -- print(#t, t[#t]) -- os.exit() for iq = 1, q do local n = io.read() n = lltonumber(n) if n == 1LL then print(1) else local pos = lower_bound(t, n) if pos == 1 then print(2) else local ans = tostring(t[pos - 1] + 1LL):gsub("LL", "") print(ans) end end end -- print(os.clock())