How about we characterize an augmentation activity between a string an and a positive integer x: a⋅x is the string that is an aftereffect of composing x duplicates of a consistently. For instance, "abc" ⋅ 2 = "abcabc", "a" ⋅ 5 = "aaaaa". A string an is separable by another string b if there exists an integer x with the end goal that b⋅x=a. For instance, "abababab" is
Correct answer will be upvoted else downvoted. Computer science.
How about we characterize an augmentation activity between a string an and a positive integer x: a⋅x is the string that is an aftereffect of composing x duplicates of a consistently. For instance, "abc" ⋅ 2 = "abcabc", "a" ⋅ 5 = "aaaaa".
A string an is separable by another string b if there exists an integer x with the end goal that b⋅x=a. For instance, "abababab" is separable by "stomach muscle", however isn't detachable by "ababab" or "aa".
LCM of two strings s and t (characterized as LCM(s,t)) is the briefest non-void string that is separable by both s and t.
You are given two strings s and t. Find LCM(s,t) or report that it doesn't exist. It very well may be shown that if LCM(s,t) exists, it is interesting.
Input
The main line contains one integer q (1≤q≤2000) — the number of experiments.
Each experiment comprises of two lines, containing strings s and t (1≤|s|,|t|≤20). Each character in every one of these strings is either 'a' or 'b'.
Output
For each experiment, print LCM(s,t) if it exists; in any case, print - 1. It tends to be shown that if LCM(s,t) exists, it is novel.
Step by step
Solved in 4 steps with 1 images