{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"PLAIN","content":"我们定义一个字符串a乘一个数字x,即a*x表示将a这个字符串重复x遍,比如\"abc\"*2\u003d\"abcabc\",\"a\"*5\u003d\"aaaaa\"。\n\n我们称一个字符串a能被另一个字符串b整除,当且仅当存在一个整数x使得b*x\u003da。比如,\"abababab\"能被\"ab\"整除,但不能被\"ababab\"或者\"aa\"整除。\n\n接下来我们定义两个字符串s与t的LCM,记为LCM(s,t),为一个能够同时被s与t整除的最短非空字符串。\n\n现在给定字符串s与字符串t,求LCM(s,t)。如果不存在请输出-1。可以证明若LCM(s,t)存在,则其唯一."}},{"title":"Input","value":{"format":"PLAIN","content":"第一行只有一个正整数q(1\u003c\u003dq \u003c\u003d2000)表示数据组数。\n\n每一组数据包含两行字符串s与t(1\u003c\u003d|s|,|t|\u003c\u003d20)。s与t只由字符\u0027a\u0027或字符\u0027b\u0027组成。"}},{"title":"Output","value":{"format":"PLAIN","content":"对每组数据,若LCM(s,t)存在,输出LCM(s,t),若不存在,输出-1。"}},{"title":"Example","value":{"format":"PLAIN","content":"Input\n3\nbaba\nba\naa\naaa\naba\nab\n\nOutput\nbaba\naaaaaa\n-1\n"}},{"title":"Note","value":{"format":"PLAIN","content":"第一个样例,因为\"ba\"*2\u003d\"baba\"。\n第二个样例,\"aa\"*3\u003d\"aaaaaa\",\"aaa\"*2\u003d\"aaaaaa\"。"}}]}