Illya has $n$ magic numbers. The $i_{th}$ number $a_i$ can be represented by a binary with the length of $i$. Combining these $0-1$ strings gets a long string $s$ with the length of $\frac{n(n+1)}{2}$. The $0-1$ strings from $s_{\frac{i(i-1)}{2}}$ to $s_{\frac{i(i+1)}{2}-1}$ is the binary of $a_i$ from low to high.
One day, Rin input Illya’s magic numbers into a program to create $n$ new magic numbers. The $i_{th}$ new number is $b_i$.
Here is the code of program in C++:
for(int i = 1; i <= n; i++)
b[i] = flag[i] = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if( (1 << (j - 1) & a[i]) > 0){
if(!flag[i])
b[i] = b[j], flag[i] = 1;
else b[i] &= b[j];
}
}
b[i] ^= 1 << (i - 1);
}
After that, Rin leave $q$ questions. The $i_{th}$ question is a number $c_i$, which can be represented by a binary with the length of $len_i$. Combining these $0-1$ strings gets a long string $t$ with the length of $L_q$ ($L_k = \sum_{1}^{k}len_i$). The $0-1$ strings from $t_{L_{i-1}}$ to $t_{L_i-1}$ is the binary of $c_i$ from low to high.
For each question, Rin requires Illya to calculate number $d_i$.
for(int i = 1; i <= n; i++){
d[i] = 0;
for(int j = 1; j <= len[i]; j++)
if(j <= n && (1 << (j - 1) & c[i]) > 0)
d[i] |= b[j];
}
The answer of $i_{th}$ question is the number of ones in the binary of $d_i$.