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 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 -- print(t[1]) -- print(#t, t[#t]) -- os.exit() local a = {} local aidx = {} local ans = {} for iq = 1, q do aidx[iq] = iq local z = io.read() z = string.rep("0", 19 - #z) .. z a[iq] = z ans[iq] = 0 end table.sort(aidx, function(x, y) return a[x] < a[y] end) print("!") os.exit() local tpos = 1 for iq = 1, q do local i = aidx[iq] local n = lltonumber(a[i]) if n == 1LL then ans[i] = 1 else while tpos <= #t and t[tpos] < n do tpos = tpos + 1 end if tpos == 1 then ans[i] = 2 else ans[i] = tostring(t[tpos - 1] + 1LL):gsub("LL", "") end end end print(table.concat(ans, "\n"))