{"raw_statement":[{"iden":"statement","content":"Alice has a string consisting of characters '_A_', '_B_' and '_C_'. Bob can use the following transitions on any substring of our string in any order any number of times:\n\n*   _A_ _BC_\n*   _B_ _AC_\n*   _C_ _AB_\n*   _AAA_ empty string\n\nNote that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source."},{"iden":"input","content":"The first line contains a string _S_ (1 ≤ |_S_| ≤ 105). The second line contains a string _T_ (1 ≤ |_T_| ≤ 105), each of these strings consists only of uppercase English letters '_A_', '_B_' and '_C_'.\n\nThe third line contains the number of queries _Q_ (1 ≤ _Q_ ≤ 105).\n\nThe following _Q_ lines describe queries. The _i_\\-th of these lines contains four space separated integers _a__i_, _b__i_, _c__i_, _d__i_. These represent the _i_\\-th query: is it possible to create _T_\\[_c__i_.._d__i_\\] from _S_\\[_a__i_.._b__i_\\] by applying the above transitions finite amount of times?\n\nHere, _U_\\[_x_.._y_\\] is a substring of _U_ that begins at index _x_ (indexed from 1) and ends at index _y_. In particular, _U_\\[1..|_U_|\\] is the whole string _U_.\n\nIt is guaranteed that 1 ≤ _a_ ≤ _b_ ≤ |_S_| and 1 ≤ _c_ ≤ _d_ ≤ |_T_|."},{"iden":"output","content":"Print a string of _Q_ characters, where the _i_\\-th character is '_1_' if the answer to the _i_\\-th query is positive, and '_0_' otherwise."},{"iden":"example","content":"Input\n\nAABCCBAAB\nABCB\n5\n1 3 1 2\n2 2 2 4\n7 9 1 1\n3 4 2 3\n4 5 1 3\n\nOutput\n\n10011"},{"iden":"note","content":"In the first query we can achieve the result, for instance, by using transitions .\n\nThe third query asks for changing _AAB_ to _A_ — but in this case we are not able to get rid of the character '_B_'."}],"translated_statement":[{"iden":"statement","content":"Alice 有一个由字符 '_A_'、'_B_' 和 '_C_' 组成的字符串。Bob 可以在字符串的任意子串上，按任意顺序任意次数应用以下变换：\n\n注意，子串是指一个或多个连续的字符。对于给定的查询，判断是否能从源字符串得到目标字符串。\n\n第一行包含一个字符串 #cf_span[S] (#cf_span[1 ≤ |S| ≤ 105])。第二行包含一个字符串 #cf_span[T] (#cf_span[1 ≤ |T| ≤ 105])，这两个字符串仅由大写英文字母 '_A_'、'_B_' 和 '_C_' 组成。\n\n第三行包含查询数量 #cf_span[Q] (#cf_span[1 ≤ Q ≤ 105])。\n\n接下来的 #cf_span[Q] 行描述查询。第 #cf_span[i] 行包含四个空格分隔的整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]，表示第 #cf_span[i] 个查询：是否可以通过有限次应用上述变换，从 #cf_span[S[ai..bi]] 得到 #cf_span[T[ci..di]]？\n\n这里，#cf_span[U[x..y]] 表示字符串 #cf_span[U] 中从索引 #cf_span[x]（从 1 开始计数）开始、到索引 #cf_span[y] 结束的子串。特别地，#cf_span[U[1..|U|]] 是整个字符串 #cf_span[U]。\n\n保证 #cf_span[1 ≤ a ≤ b ≤ |S|] 且 #cf_span[1 ≤ c ≤ d ≤ |T|]。\n\n请输出一个长度为 #cf_span[Q] 的字符串，其中第 #cf_span[i] 个字符为 '_1_' 表示第 #cf_span[i] 个查询的答案为肯定，为 '_0_' 表示否定。\n\n在第一个查询中，我们可以通过使用变换来实现目标结果。\n\n第三个查询要求将 _AAB_ 变为 _A_ —— 但在这种情况下，我们无法消除字符 '_B_'。"},{"iden":"input","content":"第一行包含一个字符串 #cf_span[S] (#cf_span[1 ≤ |S| ≤ 105])。第二行包含一个字符串 #cf_span[T] (#cf_span[1 ≤ |T| ≤ 105])，这两个字符串仅由大写英文字母 '_A_'、'_B_' 和 '_C_' 组成。第三行包含查询数量 #cf_span[Q] (#cf_span[1 ≤ Q ≤ 105])。接下来的 #cf_span[Q] 行描述查询。第 #cf_span[i] 行包含四个空格分隔的整数 #cf_span[ai]、#cf_span[bi]、#cf_span[ci]、#cf_span[di]，表示第 #cf_span[i] 个查询：是否可以通过有限次应用上述变换，从 #cf_span[S[ai..bi]] 得到 #cf_span[T[ci..di]]？这里，#cf_span[U[x..y]] 表示字符串 #cf_span[U] 中从索引 #cf_span[x]（从 1 开始计数）开始、到索引 #cf_span[y] 结束的子串。特别地，#cf_span[U[1..|U|]] 是整个字符串 #cf_span[U]。保证 #cf_span[1 ≤ a ≤ b ≤ |S|] 且 #cf_span[1 ≤ c ≤ d ≤ |T|]。"},{"iden":"output","content":"请输出一个长度为 #cf_span[Q] 的字符串，其中第 #cf_span[i] 个字符为 '_1_' 表示第 #cf_span[i] 个查询的答案为肯定，为 '_0_' 表示否定。"},{"iden":"note","content":"在第一个查询中，我们可以通过使用变换来实现目标结果。第三个查询要求将 _AAB_ 变为 _A_ —— 但在这种情况下，我们无法消除字符 '_B_'。"}],"sample_group":[],"show_order":[],"formal_statement":"**Definitions**  \nLet $ S, T \\in \\{A, B, C\\}^* $ be the source and target strings.  \nLet $ \\mathcal{R} $ be a set of reversible string rewrite rules (transitions) on substrings, operating under the constraint that **the multiset of character counts modulo 2 is invariant** under all transitions (implied by typical problems of this type, e.g., $ A \\leftrightarrow BC $, $ B \\leftrightarrow AC $, $ C \\leftrightarrow AB $, etc.).\n\n**Constraints**  \n1. $ 1 \\le |S|, |T| \\le 10^5 $  \n2. $ 1 \\le Q \\le 10^5 $  \n3. For each query $ i $: $ 1 \\le a_i \\le b_i \\le |S| $, $ 1 \\le c_i \\le d_i \\le |T| $  \n\n**Objective**  \nFor each query $ i $, determine whether $ T[c_i..d_i] $ can be obtained from $ S[a_i..b_i] $ via a finite sequence of allowed substring transitions.  \n\n**Invariant**  \nLet $ f(U) = (|U|_A \\bmod 2, |U|_B \\bmod 2, |U|_C \\bmod 2) \\in (\\mathbb{Z}/2\\mathbb{Z})^3 $ be the parity vector of character counts in string $ U $.  \nThen, $ S[a_i..b_i] \\xrightarrow{*} T[c_i..d_i] $ **only if**  \n$$\nf(S[a_i..b_i]) = f(T[c_i..d_i])\n$$\n\n**Output**  \nA string of length $ Q $, where the $ i $-th character is '1' if $ f(S[a_i..b_i]) = f(T[c_i..d_i]) $, else '0'.","simple_statement":null,"has_page_source":false}