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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education