1. Abridged Problem Statement  
   Given a positive integer N (1 ≤ N ≤ 10^18), we list all positive integers whose decimal representation does *not* contain the substring "13", in increasing order. Find the N-th number in that list. There are up to T (≤100) test cases.

2. Detailed Editorial  

   Idea: We need to handle N as large as 10^18, so we cannot generate numbers one by one. Instead, we  
   a) Count, for any given bound X, how many integers in [0…X] do *not* contain "13".  
   b) Binary‐search on X to find the smallest X for which that count (minus one for zero) is ≥ N.

   A. Counting with Digit DP  
   - Represent X as a string of digits `D[0..L-1]`.  
   - Define `dp[pos][last_is_1][is_tight]` = number of ways to fill digits from `pos` to `L-1` such that we never form "13", given:  
     • `last_is_1` = 1 if the previous digit was '1', else 0.  
     • `is_tight` = 1 if the prefix so far exactly matches X's prefix (so next digit is bounded by D[pos]), else 0 (we already put something smaller, so we can use 0–9).  
   - Transition: at position `pos`, choose digit `d` from 0 to `up = is_tight ? D[pos] : 9`. Skip if `last_is_1==1 && d==3` (that would form "13").  
     new_last_is_1 = (d==1), new_is_tight = is_tight && (d==up).  
   - Base case: pos==L → 1 valid way (the number built so far is OK).  
   - Memoize by `dp[pos][last_is_1][is_tight]`. Complexity: O(L · 2 · 2 · 10) ≈ 19·40 = 760 ops per call.

   B. Binary Search  
   - We want the N-th valid positive integer. Let `count(X)` = number of valid ints in [0..X]. Note `count(0)=1` (the 0 itself). We exclude zero from ranking by subtracting 1.  
   - Find the minimum `X` such that `count(X) - 1 ≥ N`. Standard binary search on X in [1..2N] (we know the N-th valid can't exceed 2N because at worst half of numbers are invalid, so an upper bound is 2N).

   Per test case:  
   1) Read N.  
   2) Binary search X. Each mid-value requires one digit-DP pass of ~O(760).  
   3) Output the found X.

3. Provided C++ Solution with Detailed Comments  

```
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;

// We'll use a digit-DP to count how many numbers ≤ bound do not contain "13".
int64 n;  // target index N
string bound_s;  // decimal string of current search bound
// dp[pos][last1][tight]: -1 means uncomputed, else stores the count
vector<array<array<int64,2>,2>> dp;

// Recursive digit-DP function
// pos: current digit position (0..L-1)
// last1: 1 if previous digit was '1', else 0
// tight: 1 if prefix is exactly bound_s[0..pos-1], else 0 (allows choosing 0–9 freely)
int64 rec(int pos, int last1, int tight) {
    // If we've placed all digits, there is exactly 1 valid number so far.
    if (pos == (int)bound_s.size()) {
        return 1;
    }
    // Memo lookup
    int64 &res = dp[pos][last1][tight];
    if (res != -1) return res;
    res = 0;
    // Maximum digit we can place
    int limit = tight ? bound_s[pos] - '0' : 9;
    // Try every digit from 0 to limit
    for (int d = 0; d <= limit; d++) {
        // If last digit was '1' and we place '3', we form "13" → skip
        if (last1 && d == 3) continue;
        // Compute next states
        int next_last1 = (d == 1);
        int next_tight = tight && (d == limit);
        res += rec(pos+1, next_last1, next_tight);
    }
    return res;
}

// Count how many integers in [0..bound] have no "13"
int64 count_upto(int64 bound) {
    bound_s = to_string(bound);
    int L = bound_s.size();
    // reset dp to -1
    dp.assign(L, {{{-1,-1},{-1,-1}}});
    return rec(0, 0, 1);
}

void solve_case() {
    // Binary search on X in [1..2N], find minimal X s.t. count_upto(X)-1 ≥ N
    int64 lo = 1, hi = 2*n, ans = hi;
    while (lo <= hi) {
        int64 mid = lo + (hi - lo)/2;
        // subtract 1 to remove zero from the count
        if (count_upto(mid) - 1 >= n) {
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    cout << ans << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        solve_case();
    }
    return 0;
}
```

4. Python Solution with Detailed Comments  

```python
import sys
sys.setrecursionlimit(10000)

def count_upto(bound):
    """
    Return how many numbers in [0..bound] do not contain substring '13'.
    We use digit DP with memoization.
    """
    s = str(bound)
    L = len(s)
    # dp[pos][last1][tight] = count of ways; use dict or list initialized to None
    dp = [[[None]*2 for _ in range(2)] for __ in range(L)]
    
    def rec(pos, last1, tight):
        # If at end, there's exactly one valid number
        if pos == L:
            return 1
        if dp[pos][last1][tight] is not None:
            return dp[pos][last1][tight]
        limit = int(s[pos]) if tight else 9
        res = 0
        for d in range(0, limit+1):
            # Skip forming "13"
            if last1 and d == 3:
                continue
            nxt_last1 = 1 if d == 1 else 0
            nxt_tight = tight and (d == limit)
            res += rec(pos+1, nxt_last1, nxt_tight)
        dp[pos][last1][tight] = res
        return res

    return rec(0, 0, True)

def find_nth(n):
    # binary search X in [1..2n]
    lo, hi = 1, 2*n
    ans = hi
    while lo <= hi:
        mid = (lo+hi)//2
        # subtract 1 to ignore the count for zero
        if count_upto(mid) - 1 >= n:
            ans = mid
            hi = mid - 1
        else:
            lo = mid + 1
    return ans

def main():
    data = sys.stdin.read().strip().split()
    T = int(data[0])
    idx = 1
    out = []
    for _ in range(T):
        n = int(data[idx]); idx += 1
        out.append(str(find_nth(n)))
    print("\n".join(out))

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  
   - Use digit‐DP to count numbers ≤ X without substring "13".  
   - DP state: (pos, last_was_1, is_tight).  
   - For query N, binary‐search the smallest X with count(X)−1 ≥ N.  
   - Answer is that X.