Substrings with Shift
You are given K texts, all of which have the same length.
Your task is to determine how to find a substring with a shift. A substring S with shifts a_1, a_2, ..., a_K is considered to be present in the set of K texts T_1, T_2, ..., T_K if there exists a number x such that for every i, LCP(T_i + a_i + x, S) is at least |S|. Here, LCP refers to the length of the longest common prefix, (T_i + j) denotes the j-th suffix of the string T_i, and |S| is the length of the string S.
Input
The number K is between 1 and 10, and there are K texts, each having the same length ranging from 1 to 10^5. Next, you are given M, which ranges from 1 to 10^5, representing the number of queries, followed by the queries themselves. Each query consists of a string and K numbers ranging from -10^9 to 10^9. The total length of all strings in the queries does not exceed 10^5. All strings and texts consist solely of lowercase English alphabet letters. Each string S in the queries is unique.
Output
For each query, output NO if the substring cannot be found, or YES x if it can, where x is the value that satisfies the condition.