const gcd = (a, b) => {
  while (b) {
    const w = b;
    b = a % b;
    a = w;
  }
  return a;
};

const lcm = (s, t) => {
  const length = Math.floor((s.length * t.length) / gcd(s.length, t.length));
  s = s.repeat(Math.floor(length / s.length));
  t = t.repeat(Math.floor(length / t.length));
  if (s === t) return s;
  return -1;
};

const main = () => {
  let test = parseInt(readline());
  while (test--) {
    const s = readline();
    const t = readline();
    console.log(lcm(s, t));
  }
};

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});

process.stdin.on("end", () => {
  inputString = inputString
    .trim()
    .split("\n")
    .map(string => string.trim());
  main();
});

const readline = () => {
  return inputString[currentLine++];
};

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var a = readline()
    var b = readline()
    var s = a
    if (a.length > b.length) {
      a = b
      b = s
    }

    var ss = ''
    for (let i = 0; i < a.length; i++) {
      ss += a[i]
      if (a.length % ss.length === 0 && ss.repeat(a.length / ss.length) === a &&
        b.length % ss.length === 0 && ss.repeat(b.length / ss.length) === b
      ) {
        var len = ss.length
        var count = 1
        while (len % a.length !== 0 || len % b.length !== 0) {
          count++
          len += ss.length
        }
        // console.log(ss, count, len, len % a.length !== 0, len % b.length !== 0)
        console.log(ss.repeat(count))
        return
      }
    }
    console.log(-1)

  })

}

function gcd(a, b) {
  if (!b) {
    return a;
  }

  return gcd(b, a % b);
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  const LCM = (n1, n2) => {
    let i = 1,
      t = n1;
    while (n1 % n2 !== 0) {
      n1 = t * i;
      i++;
    }
    return n1;
  };
  while (t--) {
    let str1 = readline().trim().split("");
    let str2 = readline().trim().split("");
    let len = LCM(str1.length, str2.length);
    let n1 = [],
      n2 = [];
    for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);
    for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);
    let ans = true;
    for (let i = 0; i < len; i++) {
      if (n1[i] !== n2[i]) {
        ans = false;
        break;
      }
    }
    console.log(`${ans === true ? n1.join("") : -1}`);
  }
};
solve();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}
function gcd(a, b) {
	if (b === 0) return a;
	return gcd(b, a % b);
}

function main() {
	let t = +readLine();
	while (t--) {
		const s1 = readLine();
		const s2 = readLine();
		let [small, large] = ['', ''];
		if (s1 < s2) {
			[small, large] = [s1, s2];
		} else {
			[small, large] = [s2, s1];
		}
		const [smallLen, largeLen] = [small.length, large.length];
		if (largeLen % smallLen === 0) {
			if (small.repeat(largeLen / smallLen) === large) console.log(large);
			else console.log(-1);
		} else {
			let len = Math.floor((smallLen * largeLen) / gcd(smallLen, largeLen));
			if (small.repeat(len / smallLen) === large.repeat(len / largeLen)) {
				console.log(small.repeat(len / smallLen));
			} else console.log(-1);
		}
	}
}

const readline = require('readline');
const { stdin: input, stdout: output } = require('process')
const rl = readline.createInterface({ input, output })

let lines = []

const createReadLine = () => {
  i = 0;
  return () => lines[i++]
}

rl.on('line', line => lines.push(line))

function divided(a, b) {
  return a.split(b).join('').length ? false : true;
}

function gcd(a, b) {
	if (!a || !b) return 0

	while (true) {
		if ((a %= b) === 0)
			return Math.abs(b);
		else if ((b %= a) === 0)
			return Math.abs(a);
  }
}

rl.on("close", () => {
  const readLine = createReadLine();
  let t = parseInt(readLine());
  while (t--) {
    let a = readLine(),
        b = readLine()

    const lcm = (a.length * b.length / gcd(a.length, b.length))

    if (a.length < b.length) [a, b] = [b, a]
    const str = b.repeat(lcm / b.length)

    if (divided(str, a) && divided(str, b)) {
      console.log(str)
    }
    else {
      console.log(-1)
    }
  }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var A = next();
		var B = next();
		var l = lcm(A.length, B.length);
		var nA = new Array(l / A.length).fill(A).join("");
		var nB = new Array(l / B.length).fill(B).join("");
		if(nA == nB){
			myout(nA);
		}else{
			myout(-1);
		}
	}
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main()
});

function readline() {
  return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let testCases = readline()
  while(testCases--)
    solve()
}

// function to solve problems
function solve (){
  let firstWord = readline()
  let secondWord = readline()
  let smallWord = '', largeWord = '', ans = ''
  // ====== SOLUTION ======
  // console.log(`Firstword = ${firstWord} | secondWord = ${secondWord}`)
  if (firstWord.length < secondWord.length) {
    smallWord = firstWord
    largeWord = secondWord
  } else {
    largeWord = firstWord
    smallWord = secondWord
  }
  if (!isCompleteSubstring(smallWord, largeWord)) {
    console.log(-1)
    return
  }
  // get length from here
  const smallWordLength = smallWord.length
  const largeWordLength = largeWord.length

  const lcm = (largeWordLength * smallWordLength)/gcd(smallWordLength, largeWordLength)
  // console.log(`lcm = ${lcm}`)
  let factor = lcm/largeWordLength
  // ans = largeWord
  while (factor--) {
    ans += largeWord
  }
  console.log(ans)
}

function isCompleteSubstring(smallWord, largeWord) {
  if (!largeWord.includes(smallWord))
    return false

  let newWord = largeWord + smallWord
  smallWord += largeWord
  // console.log(`SmallWOr =  ${smallWord} | largeWord = ${newWord}`)
  if (smallWord !== newWord)
    return false
  return true
}
function gcd(a, b) {
  // console.log(`a = ${a}, b = ${b}`)
  if(a == 0)
    return b
  return gcd(b % a, a)
}

const readline = require("readline");
const leScan = readline.createInterface({
	input: process.stdin,
	output: process.stdout
	//terminal: false
});

toggle = true;
i1 = 0;
leScan.on("line", (input) => {
	if (i1 == 0)
	{
		i1 = 3; //Ok we went over i1
		return;
	}

	if (toggle)
	{
		i1 = input;
		toggle = false;
	}
	else
	{
		console.log(lcm(i1, input));
		toggle = true;
	}
});

const lcm = (s1, s2) => {
	let s1Construct = s1;
	let s2Construct = s2;

	/*//Makes sure a GCF actually exists or the LCM will never exist lmao
	if (findGCF(s1, s2) == -1)
	{
		return -1;
	}*/

	while (s1Construct != s2Construct)
	{
		if (s1Construct.length < s2Construct.length)
		{
			s1Construct += s1;
		}
		else if (s1Construct.length == s2Construct.length) //If it's equal, then it means we're hopeless and a LCM does not exist
		{
			return -1;
		}
		else //if s2Construct.length < s1Construct.length
		{
			s2Construct += s2;
		}
	}

	return s1Construct;
}

/*const cm = (str) => {
	let gcf = "";
	let currchain = "";

	for (var i=0; i < str.length; i++)
	{
		currchain += str[i];

		var currdex = currchain.length - 1;

		//Checks if the currchain matches the gcf (% accounts for repeats). If it doesn't, we know the gcf + currChain is the cm
		if (currchain[currdex] != gcf[currdex % gcf.length])
		{
			gcf += currchain;
			currchain = "";
		}
	}

	//Returns the gcf and the number of times the gcf repeats in the string. Should be an int if a gcf exists
	return [gcf, str.length / gcf.length];
}

const lcm = (s1, s2) => {
	if (s2.length < s1.length)
	{
		var temp = s2;
		s2 = s1; //convience purposes lol
		s1 = temp;
	}

	let gcf = findGCF(s1, s2);

	if (gcf == -1)
	{
		return -1;
	}
	else
	{
		//Modify s1 until it matches s2 using the gcf

		while (s1 != s2)
		{

		}
	}
}*/

const findGCF = (s1, s2) => {
	if (s2.length < s1.length)
	{
		var temp = s2;
		s2 = s1; //convience purposes lol
		s1 = temp;
	}

	//Modified Euler GCF formula lmao
	//But this is easier as last index will be remainder
	//tracker keeps track of how many times we have splitted s2
	var arr = s2.split(s1);
	var gcf = arr[0];
	var remainder = arr[arr.length - 1];

	//If the function did not make the gcf length less, then we know that it's hopeless and we should just return -1
	if (gcf.length == s2.length)
	{
		return -1;
	}

	//When gcf == remainder, the remainder is "0"
	return gcf == remainder ? gcf : findGCF(gcf, remainder);
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout,
})

const calculate = (a, b) => {
  if (a < b) {
    const temp = a
    a = b
    b = temp
  }

  let tempA = a
  let tempB = b

  while (tempA.length !== tempB.length) {
    if (tempA.length > tempB.length) {
      tempB += b
    } else {
      tempA += a
    }
  }

  return tempA === tempB ? tempA : -1
}

let index = -1
let maxRound = 0
let round = 0

let a, b
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 2
    if (mode === 0) {
      a = line
    } else if (mode === 1) {
      b = line
      answer.push(calculate(a, b))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

// chainNumberList, cList, aList, bList
// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))

/*
 * File Created: Thursday, 14th January 2021 3:54:21 pm
 * Author: Lukas Rimkus
 */

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine(), 10);

    while(testCases--) {

        const s = readLine();

        const t = readLine();

        const res = b(s,t);

        console.log(res);
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function a(n, d, arr){

    arr.sort((a,b) => a - b);
    // console.log(arr)
    for(let i = 0; i < n ; i++){
        if(arr[i] <= d) continue;
        if(arr[i] > d){
            if(arr[0] + arr[1] <= d && i !== 0 && i !== 1 ){
                continue;
            }
            if(i === 0){
                if(arr[1] + arr[2] <= d) continue;
            }
            if(i === 1){
                if(arr[0] + arr[2] <= d) continue;
            }
        }
        return 'NO'
    }
    return 'YES'
}

function gcd(a,b){
    if(b === 0) return a;
    else{
        return gcd(b, a % b)
    }
}

function lcm(a,b){
    return (a * b) / gcd(a,b)
}

function mul(s, k) {
    let res = '';
    while(k--) res += s;
    return res;
}

function b(s,t){
    const n = s.length;
    const m = t.length;
    const g = gcd(n,m);
    // console.log('gcd(n,m) = ',g,'mul(s,m/g) = ', mul(s, m/ g), 'mul(t,n/g) = ', mul(t, n / g), 'm/g = ', m/g, 'n/g = ', n/g)
    if(mul(s,m /g) === mul(t, n / g)){
        return mul(s, m / g);
    } else {
        return -1;
    }
}

module.exports = b;

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline(), sn = "";
        let t = readline(), tn = "";
        let c = false;
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        let tl = s.length/gcd(s.length, t.length);
        for(let i = 0; i < sl; i++)sn +=s;
        for(let i = 0; i < tl; i++)tn +=t;
        print(sn == tn ? sn : -1);
    }

"use strict"

let iter = parseInt(readline());

for(iter; iter > 0; iter--){
    let a = readline();
    let b = readline();

    let str1 = b;
    let str2 = a;

    let gcd = greatestCommonDivisor(a.length, b.length)

    let i1 = a.length / gcd;
    let i2 = b.length / gcd;
    for(i1; i1 > 1; i1--){
        str1 += b;
    }
    for(i2; i2 > 1; i2--){
        str2 += a;
    }

    if(str1 === str2){
        print(str1);
    } else {
        print(-1);
    }
}

function greatestCommonDivisor(a, b){
    if(b === 0) return a;
    return greatestCommonDivisor(b, a % b);
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1*d2)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(sL, tL, stringL)
    // console.log(ans, sL % tL, tL % tL)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)
        if(sL % tL === 0) return s
        if(tL % sL === 0) return t

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (tL*sL/stringL / stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(sL, tL, stringL)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (tL*sL/stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(ans)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1*d2/stringL)
    // console.log(string.repeat(d1), s, string.repeat(d2), t)
    // console.log(ans)
    // console.log(ans)
    ans = ans === 0 ? 1 : ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {
        if(d1 === 1) return string.repeat(d2)
        if(d2 === 1) return string.repeat(d1)

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    // console.log(sL % stringL, tL % stringL)
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2
    // console.log(string.repeat(d1),s, string.repeat(d2), t)
    // console.log(ans)
    ans = ans === 0? 1: ans
    if (string.repeat(d1) === s && string.repeat(d2) === t) {

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    var d1 = sL / stringL
    var d2 = tL / stringL
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    var ans = (d1===1 ?0:d1 + d2===1 ?0:d2) *2
    if (string.repeat(d1) === s && string.repeat(d2) === t) {

        return string.repeat(ans)
    }
    return false
}

// 'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var s = readline();
        var t = readline();
        var min = s.length < t.length ? s : t
        // console.log(s, t)
        var l = min.length
        var string = ''
        var answer = false
        for (var i = 1; i <= l; i++) {
            string = min.substring(0, i)
            // console.log(string)
            var check = checkString(string, s, t)
            if (check) {
                return console.log(check)
            }
        }
        console.log(-1)

    })

}

function checkString(string, s, t) {
    var stringL = string.length
    var sL = s.length
    var tL = t.length
    if (sL % stringL !== 0 || tL % stringL !== 0) return false
    if (string.repeat(sL / stringL) === s && string.repeat(tL / stringL) === t) return string.repeat(sL / stringL + tL / stringL)
    return false
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let str1 = readline().trim().split("");
    let str2 = readline().trim().split("");
    let len;
    if (str1.length > str2.length)
      len =
        str1.length % str2.length === 0
          ? str1.length
          : str1.length * str2.length;
    else
      len =
        str2.length % str1.length === 0
          ? str2.length
          : str1.length * str2.length;
    let n1 = [],
      n2 = [];
    for (let i = 0; i < len; i++) n1.push(str1[i % str1.length]);
    for (let i = 0; i < len; i++) n2.push(str2[i % str2.length]);
    let ans = true;
    for (let i = 0; i < len; i++) {
      if (n1[i] !== n2[i]) {
        ans = false;
        break;
      }
    }
    console.log(`${ans === true ? n1.join("") : -1}`);
  }
};
solve();

let inputString = '';
let currentLine = 0;
process.stdin.on('data', (data) => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map((str) => str.trim());
	main();
});
function readLine() {
	return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
	for (var a = arguments, r = a[0], i = a.length; --i; )
		r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
	return r;
}
function inv(b) {
	for (var a = MOD, u = 0, v = 1, t; b; v = t)
		(t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
	u %= MOD;
	return u < 0 ? u + MOD : u;
}
function pow(base, n) {
	if (n === 0) return 1;
	let p = pow(base, Math.floor(n / 2));
	let res = mul(mod(p), mod(p));
	if (n % 2 === 1) res = mul(mod(res), base);
	return res;
}
function highestOneBit(i) {
	i |= i >> 1;
	i |= i >> 2;
	i |= i >> 4;
	i |= i >> 8;
	i |= i >> 16;
	return i - (i >>> 1);
}
function permutation(arr, len, store = '', permutations = []) {
	if (store.length === len) {
		permutations.push(store);
		return;
	}
	for (let i = 0; i < arr.length; i++) {
		const newArr = [...arr];
		const newChar = newArr.splice(i, 1);
		permutation(newArr, len, store.concat(newChar), permutations);
	}
	return permutations;
}

function main() {
	let t = +readLine();
	while (t--) {
		const s1 = readLine();
		const s2 = readLine();
		let [small, large] = ['', ''];
		if (s1 < s2) {
			[small, large] = [s1, s2];
		} else {
			[small, large] = [s2, s1];
		}
		const [smallLen, largeLen] = [small.length, large.length];
		if (largeLen % smallLen === 0) {
			if (small.repeat(largeLen / smallLen) === large) console.log(large);
			else console.log(-1);
		} else {
			if (small.repeat(largeLen) === large.repeat(smallLen)) {
				console.log(small.repeat(largeLen));
			} else console.log(-1);
		}
	}
}

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline();
        let t = readline();
        let c = false;
        if(t.length > s.length)
        {
            let temp = s;
            s = t;
            t = temp;
        }
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        for(let i = 1; i < sl; i++)s+=s;
        if(s.includes(t))
        {
            c = true;
            let a = s.split(t);
            for(let i = 0; i < a.length; i++)if(a[i].length)c = false;
        }
        print(c? s : -1);
    }

'use strict'

let q = readline();
    while(q--)
    {
        let s = readline();
        let t = readline();
        let c = true;
        if(t.length > s.length)
        {
            let temp = s;
            s = t;
            t = temp;
        }
        function gcd(a, b){return (b == 0)? a : gcd(b, a % b);}
        let sl = t.length/gcd(s.length, t.length);
        for(let i = 1; i < sl; i++)s+=s;
        if(s.includes(t))
        {
            let a = s.split(t);
            for(let i = 0; i < a.length; i++)if(a[i].length)c = false;
        }
        print(c? s : -1);
    }

"use strict"

let iter = parseInt(readline());

for(iter; iter > 0; iter--){
    let a = readline();
    let b = readline();

    if(a.length > b.length){
        let bufer = b;
        b = a;
        a = bufer;
    }

    if(b.indexOf(a) === -1){
        print(-1);
    } else {
        let str = b;
        let i = a.length / greatestCommonDivisor(a.length, b.length);
        for(i; i > 1; i--){
            str += b;
        }

        if(str.slice(-b.length, str.length) === b && str.slice(-a.length, str.length) === a){
            print(str);
        } else {
            print(-1);
        }
    }
}

function greatestCommonDivisor(a, b){
    if(b === 0) return a;
    return greatestCommonDivisor(b, a % b);
}


'use strict';

function solve(n, m, a, b) {
  const l = new Array(m),
        r = new Array(m);
  for (let i = 0, j = 0; i < n; i++, j++) {
    while (a[i] !== b[j]) i++;
    l[j] = i;
  }
  for (let i = n - 1, j = m - 1; i >= 0; i--, j--) {
    while (a[i] !== b[j]) i--;
    r[j] = i;
  }
  let res = 0;
  for (let i = 0; i < m - 1; i++) {
    res = Math.max(res, r[i + 1] - l[i]);
  }
  return res;
}

async function main(read) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = await read();
      const b = await read();
      res[i] = solve(n, m, a, b);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
        j++
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
        j--

    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    // const total = +input[0];
    // for (let i = 1; i <= total; i++) {
    //    console.log(solve(input[i]));
    // }
    console.log(solve(input[1], input[2]));
    process.exit();
});

function solve(a, b) {
    const charArys = new Array(26).fill(0).map(() => []);
    for (let i = 0; i < a.length; i++) {
        const code = a[i].charCodeAt() - 97;
        charArys[code].push(i);
    }

    const pres = new Array(b.length);
    pres[0] = charArys[b[0].charCodeAt() - 97][0];
    for (let i = 1; i < b.length; i++) {
        const ary = charArys[b[i].charCodeAt() - 97];
        const pre = pres[i - 1];
        let left = 0; right = ary.length - 1;
        while (left < right) {
            const mid = (left + right) >> 1;
            if (ary[mid] > pre) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        pres[i] = ary[left];
    }
    const last = b[b.length - 1].charCodeAt() - 97;
    let max = charArys[last].pop();
    let result = max - pres[b.length - 2];
    for (let i = b.length - 2; i; i--) {
        const ary = charArys[b[i].charCodeAt() - 97];
        let left = 0; right = ary.length - 1;
        if (ary[right] < max) {
            left = right;
        } else {
            while (left < right) {
                const mid = (left + right) >> 1;
                if (ary[mid] >= max) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            left--;
        }
        max = ary[left];
        result = Math.max(result, max - pres[i - 1]);
    }
    return result;
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let [n, m] = rna();
	let s = rl();
	let t = rl();

	const lstp = Array(m);
	for (let i = n - 1, j = m - 1; j >= 0; i--) {
		if (s[i] == t[j]) {
			lstp[j--] = i;
		}
	}

	let ans = 0;
	for (let i = 0, j = 0; j < m - 1; i++) {
		if (s[i] == t[j]) {
			ans = Math.max(ans, lstp[j+1] - i);
			j++;
		}
	}

	console.log(ans);
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var N = nextInt();
	var M = nextInt();
	var s = next();
	var t = next();
	var max = 1;
	var kouho = new Array(M);
	var index = 0;
	for(var i = 0; i < N; i++){
		if(s[i] == t[index]){
			kouho[index] = {
				L : i
			};
			index++;
			if(index == M){
				break;
			}
		}
	}
	index--;
	for(var i = N - 1; i >= 0; i--){
		if(s[i] == t[index]){
			kouho[index].R = i;
			index--;
			if(index == -1){
				break;
			}
		}
	}
	//myerr(kouho);
	for(var i = 0; i < M - 1; i++){
		max = Math.max(max, kouho[i + 1].L - kouho[i].L);
	}
	for(var i = M - 1; i > 0; i--){
		max = Math.max(max, kouho[i].R - kouho[i - 1].L);
	}
	myout(max);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        j--
        pos2[i] = j
    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
    }
    var max = 1
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[i] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[i] = j
    }
    var max = 0
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[i+1] - pos1[i]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // var n = parseInt(readline())
    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var s = readline().split('').map((x, iii) => {
        return x
    })

    var t = readline().split('').map((x, iii) => {
        return x
    })
    // console.log(s)
    // console.log(t)
    var pos1 = {}, pos2 = {}
    var j = 0
    for (let i = 0; i < m; i++) {
        while (t[i] !== s[j]) j++
        pos1[t[i]] = j
    }
    j = n - 1
    // console.log('-----')
    for (let i = m-1; i >=0; i--) {
        while (t[i] !== s[j] && j>=0) {
            j--
        }
        pos2[t[i]] = j
    }
    var max = 0
    for (let i = 0; i < m-1; i++) {
        max = Math.max(max, Math.abs(pos2[t[i+1]] - pos1[t[i]]))
    }

    // console.log(pos1)
    // console.log(pos2)
    console.log(max)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    // const n = readline();

    // Array(Number(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    //
    // var map = {}
    // var [n, a, b, k] = readline().split(' ').map((x, i) => {
    //     return parseInt(x)
    // })

    var [n, m] = readline().split(' ').map((x, iii) => {
        return parseInt(x)
    })
    var a = readline().split('').map((x, iii) => {
        return x
    })
    var b = readline().split('').map((x, iii) => {
        return x
    })

    var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
    var letterMax = {}
    var letterfirst = {}

    var letterB = {}

    for (let i = 0; i < a.length; i++) {
        if (!letterMax[a[i]]) {
            letterMax[a[i]] = i
            letterfirst[a[i]] = i
        }
        letterMax[a[i]] = i
    }

    for (let i = 0; i < b.length; i++) {
        if (!letterB[b[i]]) {
            letterB[b[i]] = true
        }
    }

    var max = 0
    Object.keys(letterMax).map((key) => {
        if (letterB[key]) {
            max = Math.max(max, letterMax[key] - letterfirst[key])
        }
    })
    // console.log(letterMax)
    // console.log(letterfirst)
    console.log(max+1)

}

let text = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', str => {
    if (str === '\r\n' || str === '\n') {
        process.stdin.emit('end');
    } else {
        text += str;
    }
});

process.stdin.on('end', () => {
    const input = text.trim().replace(/\r/g, '').split('\n');
    // const total = +input[0];
    // for (let i = 1; i <= total; i++) {
    //    console.log(solve(input[i]));
    // }
    console.log(solve(input[1], input[2]));
    process.exit();
});

function solve(a, b) {
    const charArys = new Array(26).fill(0).map(() => []);
    for (let i = 0; i < a.length; i++) {
        const code = a[i].charCodeAt() - 97;
        charArys[code].push(i);
    }

    const pres = new Array(b.length);
    pres[0] = charArys[b[0].charCodeAt() - 97][0];
    for (let i = 1; i < b.length; i++) {
        const ary = charArys[b[i].charCodeAt() - 97];
        const pre = pres[i - 1];
        let left = 0; right = ary.length - 1;
        while (left < right) {
            const mid = (left + right) >> 1;
            if (ary[mid] > pre) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        pres[i] = ary[left];
    }
    const last = b[b.length - 1].charCodeAt() - 97;
    let max = charArys[last].pop();
    let result = max - pres[b.length - 2];
    for (let i = b.length - 2; i; i--) {
        const ary = charArys[b[i].charCodeAt() - 97];
        let left = 0; right = ary.length - 1;
        if (ary[right] < max) {
            left = right;
        } else {
            while (left < right) {
                const mid = (left + right) >> 1;
                if (ary[mid] > max) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            left--;
        }
        max = ary[left];
        result = Math.max(result, max - pres[i - 1]);
    }
    return result;
}

'use strict';

function solve(n, m, a, b) {
  const dp = new Array(m);
  for (let i = 0, j = 0; i < n; i++, j++) {
    let t = i,
        t1 = j;
    while (t + 1 < n && a[t + 1] === a[i]) t++;
    while (t1 + 1 < m && b[t1 + 1] === b[t1]) t1++;
    const dif = t - i - (t1 - j);
    for (let k = 0; k <= t1 - j; k++) {
      dp[j + k] = [i + k, i + k + dif];
    }
    i = t;
    j = t1;
  }
  let res = 0;
  for (let i = 0; i < m - 1; i++) {
    res = Math.max(res, dp[i + 1][1] - dp[i][0]);
  }
  return res;
}

async function main(read) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = await read();
      const b = await read();
      res[i] = solve(n, m, a, b);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


ns = readline().split(' ')
n = parseInt(ns[0], 10);

fl = readline().split(' ')

ev = 0
odd = 0

for (i = 0; i < n; ++i)
{
	if (parseInt(fl[i], 10) % 2 === 0)
		++ev;
	else
		++odd;
}

if (ev >= odd)
{
	ans = odd;
}
else
{

	ans = ev + Math.floor((odd - ev) / 3);
}

print(ans)

var nk = readline().split(' ').map(v => +v.trim());
var n = nk[0];
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < n; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 3);

  print(ans);
}

var nn = readline();
var n = parseInt(nn, 10);
var a = readline().split(" ");
var even = 0;
var odd = 0;
for (var i = 0; i < n; ++i) {
    var cur = parseInt(a[i], 10);
    if (cur % 2 === 0) {
        ++even;
    }
    else {
        ++odd;
    }
}
var ans = 0;
if (even >= odd) {
    ans = odd;
}
else {
    ans = even + ((odd - even) / 3);
}
ans = Math.floor(ans);
print(ans);

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1)
        cnto=cnto+1;
    else
        cnte=cnte+1;
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte+Math.floor((cnto-cnte)/3);
print(ans);

//var print = require('lol-io').print
//var readline = require('lol-io').readline
var n = parseInt(readline());
var t = readline().split(' ');
var a = [];
var odd = 0;
var even = 0;
for (var i=0;i<n;i++){
    a.push(parseInt(t[i]));
}
for (var i=0;i<n;i++){
    if (a[i]%2==0){
        even++;
    }
    else {
        odd++;
    }
}
if (even > odd){
    print(odd);
}
else {
    var ans = even;
    odd -= even;
    print(ans + parseInt(odd / 3));
}

var n = readline();
var arr = readline().split(" ").map(v => +v.trim());

var x = 0;
var y = 0;
for(var i = 0; i < n; i++) {
    if (arr[i] % 2 == 0) x++; else y++;
}

var res = 0;
if (x > y) res = y;
else {
    res = x;
    y = y - x;
    res = res + Math.floor(y/3);
}

print(res);

const firstLine = readline();
const n = firstLine.split(' ')[0];
var arr = readline().split(" ").map(v => +v.trim());

var ctn = 0;
var ctch = 0;
for(var i = 0; i < n; i++){
    if (arr[i] % 2 === 0)
    	ctch++;
    else ctn++;
}
// print(ctch);
// print(ctn);
var k = 0;
if (ctch <= ctn)
k = ctch;
else k = ctn;
ctch -= k;
ctn -= k;
var min = 0;
if (ctn % 3 >= parseInt(ctch / 2))
min = parseInt(ctch / 2);
else min = ctn % 3;
var ans1 = parseInt(ctn / 3) + min;
if (parseInt(ctch / 2) > ctn)
min = ctn;
else min = parseInt(ctch / 2);
var ans2 = min;
if (ctn - ans2 > 0)
ans2 += parseInt((ctn - ans2) / 3);

if (ans1 > ans2)
k += ans1;
else k += ans2;
print(k);

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var odd = 0;
var even = 0;

for (var i = 0; i < n; i++)
{
	if(a[i] % 2 === 0)
		even += 1;
	else
		odd += 1;
}

if (even > odd)
	print(odd);
else
	print(even + parseInt((odd - even)/3));

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
var hlp=(ans2-ans1)-(ans2-ans1)%3;
hlp=hlp/3;
if(ans1>ans2)
print(ans2);
else print(ans1+hlp);

    var n = readline();
    var b = readline().split(' ');
    var o = 0, e = 0;
    for (var i = 0; i < n; i ++){
        if (b[i] % 2 == 1) o ++;
        else e ++;
    }
    if (o < e)
        print(o);
    else{
        var ans = e;
        o -= e;
        ans += Math.trunc(o/3);
        print(ans);

    }

var n = readline().split(" ").map(v => +v.trim())[0];
var arr = readline().split(" ").map(v => +v.trim());
var cnt0 = 0;
var cnt1 = 0;
for (var i = 0; i < n; i++){
    var el = arr[i]
	if (el % 2 === 0){
		cnt0++;
	}
	else{
		cnt1++;
	}
}
//print(arr)

if (cnt0 > cnt1){
	print(cnt1);
}
else{
    //print(cnt1 - cnt0)
    //print(parseInt((cnt1 - cnt0) / 3))
	print(cnt0 + parseInt((cnt1 - cnt0) / 3))
}

var n = readline();
var chet = 0 , nechet = 0 , maxx=0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>=nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            if (chet>maxx)maxx=chet;
            chet++;
            nechet-=2;
        }
    if (nechet>maxx)maxx=nechet;
    print(maxx);
    }
}

var L = readline().split(' ');
var n = parseInt(L[0]);
var arr = readline().split(' ');
var ans = 0, k  = 0;
for(var i = 0;i < n;i++){
  if(parseInt(arr[i])%2 === 1) ans++;
  else k++;
}
if(k > ans) print(ans);
else{
    var d = k;
    d += ((ans-k) - ((ans-k)%3))/3;
    print(d);
}

var arr = readline().split(" ").map(v => +v.trim());
var n = arr[0];
var a = readline().split(" ").map(v => +v.trim());
kch=0
knch=0
for (var i=0;i<n;i++){
    if (a[i]%2===0){
        kch++;
    }
    else{
        knch++;
    }
}
if (knch<kch){
    print(knch);
}
else{
    print(kch+Math.floor((knch-kch)/3));
}

var n = readline();
var arr = readline().split(" ");

var nc = 0;

for(var i = 0; i < n; i++){
    nc += (arr[i] % 2 == 1);
}

var c = n - nc;
var t = nc - c;
if (t <= 0)
{
    print(nc);
}
else
{
    print(c + Math.floor(t / 3));
}

var n = parseInt(readline());
var a = readline().split(' ').map(x => parseInt(x));
var odd = 0, evn = 0;
for (var x of a) {
    if (x % 2 == 1)
        odd++;
    else
        evn++;
}
var ans = 0;
while (odd > 0 && evn > 0) ans++, odd--, evn--;
while (odd > 2) ans++, odd -= 3;
print(ans);

n=readline();
//print(n);
x=readline().split(' ');
imp=0;
pai=0;
for (i = 0; i < n; i++) {
    imp+=(x[i]%2)?1:0;
    pai+=(1-x[i]%2)?1:0;
}
print(Math.min(imp,pai)+Math.floor(Math.max(imp-pai,0)/3));

var n = Number(readline());
var bouquets = readline().split(' ').map(function(x) { return Number(x)})

var odd = 0, even = 0;
bouquets.forEach(flour => {
    if(flour % 2 == 1) odd++;
    else even++;
});

var ans = Math.min(odd, even);
if(odd > ans) {
    ans += Math.floor((odd - ans) / 3);
}
print(ans);

var n = parseInt(readline());
var v = readline().split(' ').map(function (x) { return parseInt(x); });

var p = 0
var np = 0

for(var i = 0; i < n; ++i) {
    if(v[i] % 2 === 0) {
        ++p
    } else {
        ++np
    }
}

var ans = p
if(ans > np) {
    ans = np
}

np = np - ans;
ans = ans + Math.floor(np / 3)
print(ans)

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}

var ans = Math.min(num0s,num1s);
num1s -= ans;
ans += Math.floor(num1s/3);
print(ans);

var a = readline().split(' ');
var b = readline().split(' ');

var odd = 0;
var even = 0;
for(var i = 0; i < a; i++) {
	if(Number(b[i])%2===0)
	{
		even++;
	}else odd ++;

}
var ans = 0;
while(odd>0)
{
	if(even>0)
	{
		even--;
		odd--;
		ans ++;
		continue;
	}
	else{
		if(odd == 1)
		{
			//ans--;
			break;
		}
		if(odd == 2)
		{
			break;
		}
		odd-=3;
		ans++;
	}

}
if(ans<0)ans = 0;
print(ans)

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}

if(odd > even){
      odd -= even;
      var ans = even + Math.floor (odd / 3);
	print(ans);
}else	print(odd);

n=readline().split(' ').map(Number);
a=readline().split(' ').map(Number);
k=0;
for(i=0;i<n;i++) if (a[i]%2==0) k++;
z=n-k;
if (k>z){
	print(z);
}else{
	print(k+Math.floor((z-k)/3));
}

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);

}
print(ans)

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
if(ans>n-ans){
	var tot=ans-(n-ans);
	tot-=tot%3;
	ans=(n-ans)+tot/3;
}
print(ans)

var arr = readline().split(" ").map(v => +v.trim());

arr1 = readline().split(" ").map(v => +v.trim());
var c_ch = 0, c_n = 0;
for (var i = 0; i < arr1.length; ++i) {
    if (arr1[i] % 2 === 0) {
        c_ch++;
    } else {
        c_n++;
    }
}
if (c_ch < c_n) {
    print(c_ch + (c_n - c_ch - ((c_n - c_ch) % 3)) / 3);
} else {
    print(c_n);
}

var n = readline();
var arr = readline().split(" ");

var o = 0;
var e = 0;
for(var i = 0 ; i < n ; i++) {
    if(arr[i] % 2 === 0) {
        e++;
    }
    else {
        o++;
    }
}

var ans = 0;
    if(o <= e) {
        ans = o;
    }
    else {
        ans = e;
        ans = ans + Math.floor((o - e) / 3);
    }

    print(ans);

var n = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);
var a = 0;

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	x = (a - b) - (a - b)%3;
	ans += x/3;
	print(ans);
}

const n = readline();
const input = readline();
const arr = input.split(' ');

var odd = 0;
var even = 0;

for(var i = 0; i < n; i++) {
    if(arr[i]%2) {
        odd++;
    } else {
        even++;
    }
}
var ans = 0;
if(odd >= even) {
    odd-= even;
    ans = even;
    ans+= ((odd-odd%3)/3);
} else {
    ans = odd;
}
print(ans)

var n = parseInt(readline());
var a = readline().split(" ");

var i = 0;
var odd = 0;
for (; i < n; ++i)
  if (parseInt(a[i]) % 2 != 0)
    ++odd;

var even = n - odd;
if (even >= odd)
  print(odd);
else
  print(even + Math.floor((odd - even) / 3)); // lol, js divides it as float

function main() {
    // write your code here.
    // call functions `nextString`, `nextFloat` and `nextInt`
    // to read the next token of input (ignoring whitespace)
    // Alternatively, you can create your own input parser functions
    // use console.log() to write to stdout

    var n = readline();
    var b = readline().split(' ');
    var o = 0, e = 0;
    for (var i = 0; i < n; i ++){
        if (b[i] % 2 == 1) o ++;
        else e ++;
    }
    if (o < e)
        print(o);
    else
        print(e);
}

// default parsers for JS.
function nextInt() {
    return parseInt(nextString());
}

function nextFloat() {
    return parseFloat(nextString());
}

function nextString() {
    var next_string = "";
    clearWhitespaces();
    while (input_cursor < input_stdin.length && !isWhitespace(input_stdin[input_cursor])) {
        next_string += input_stdin[input_cursor];
        input_cursor += 1;
    }
    return next_string;
}

function nextChar() {
    clearWhitespaces();
    if (input_cursor < input_stdin.length) {
        return input_stdin[input_cursor++];
    } else {
        return '\0';
    }
}

//process.stdin.resume();
//process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_cursor = 0;
//process.stdin.on('data', function (data) { input_stdin += data; });
//process.stdin.on('end', function () { main(); });

function isWhitespace(character) {
    return ' \t\n\r\v'.indexOf(character) > -1;
}

function clearWhitespaces() {
    while (input_cursor < input_stdin.length && isWhitespace(input_stdin[input_cursor])) {
        // ignore the next whitespace character
        input_cursor += 1;
    }
}

main();

readline()
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 2);

  print(ans);
}

var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
  process.exit(0);
} else {
  ans += even;
  odd -= even;
}

ans += Math.floor(even / 2);

print('' + ans);

var nk = readline().split(' ').map(v => +v.trim());
var n = nk[0];
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < n; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(odd / 2);

  print(ans);
}

readline()
var arr = readline().split(' ').map(v => +v.trim());
var even = 0, odd = 0;

for (var i = 0; i < arr.length; i++) {
  if (arr[i] % 2 == 0) {
    even += 1;
  } else {
    odd += 1;
  }
}

var ans = 0;
if (even > odd) {
  print(odd);
} else {
  ans += even;
  odd -= even;

  ans += Math.floor(even / 2);

  print(ans);
}

const firstLine = readline();
const n = firstLine.split(' ')[0];
var arr = readline().split(" ").map(v => +v.trim());

var ctn = 0;
var ctch = 0;
for(var i = 0; i < n; i++){
    if (arr[i] % 2 === 0)
    	ctch++;
    else ctn++;
}
// print(ctch);
// print(ctn);
var k = 0;
if (ctch <= ctn)
k = ctch;
else k = ctn;
ctch -= k;
ctn -= k;
var min = 0;
if (ctn % 3 >= ctch / 2)
min = ctch / 2;
else min = ctn % 3;
var ans1 = ctn / 3 + min;
if (ctch / 2 > ctn)
min = ctn;
else min = ctch / 2;
var ans2 = min;
if (ctn - ans2 > 0)
ans2 += (ctn - ans2) / 3;

if (ans1 > ans2)
k += ans1;
else k += ans2;
print(k);

ns = readline().split(' ')
n = parseInt(ns[0], 10);

fl = readline().split(' ')

ev = 0
odd = 0

for (i = 0; i < n; ++i)
{
	if (parseInt(fl[i], 10) % 2 === 0)
		++ev;
	else
		++odd;
}

if (ev > odd)
	ans = odd;
else
	ans = ev;

print(ans)

var n = readline().split(" ").map(v => +v.trim())[0];
var a = readline().split(" ").map(v => +v.trim());

var odd = 0;
var even = 0;

for (var i = 0; i < n; i++)
{
	if(a[i] % 2 === 0)
		even += 1;
	else
		odd += 1;
}

if (odd > even)
	print(even);
else
	print(odd);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
var hlp=(ans1-ans2)-(ans1-ans2)%3;
hlp=hlp/3;
if(ans1>ans2)
print(ans2+hlp);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2+(ans1-ans2)/3);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2);
else print(ans1);

var n = readline();
var input = readline().split(" ");
var ans1=0;
var ans2=0;

for(var i = 0; i < n; i++){
	if(input[i] %2 ==0)
		ans1++;
	else ans2++;
}
if(ans1>ans2)
print(ans2+((ans1-ans2)/3));
else print(ans1);

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            chet++;
            nechet-=2;
        }
    print(nechet);
    }
}

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>=nechet){
    print(nechet);
}else{
    if (nechet===1){
        print(0);
    }else{
        while (chet<nechet){
            chet++;
            nechet-=2;
        }
    print(nechet);
    }
}

var n = readline();
var chet = 0 , nechet = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0; i < n; i++){
    if (arr[i]%2 === 0){
        chet++;
    }else{
        nechet++;
    }
}
if (chet>nechet){
    print(nechet);
}else{
    while (chet<nechet){
        chet++;
        nechet-=2;
    }
    print(nechet)
}

var L = readline().split(' ');
var n = parseInt(L[0]);
var arr = readline().split(' ');
var ans = 0;
for(var i = 0;i < n;i++){
  if(parseInt(arr[i])%2 === 1) ans++;
}
print(ans);

var arr = readline().split(" ").map(v => +v.trim());
var n = arr[0];
var a = readline().split(" ").map(v => +v.trim());
kch=0
knch=0
for (var i=0;i<n;i++){
    if (a[i]%2===0){
        kch++;
    }
    else{
        knch++;
    }
}
if (knch<kch){
    print(knch);
}
else{
    print(kch+(knch-kch)/3);
}

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1) {
        cnto=cnto+1;
    }
    else {
        cnte=cnte+1;
    }
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte;
print(ans);

var now=readline().split(' ').map(function(v){return +v;});
var n=now[0];
var num=readline().split(' ').map(function(v){return +v;});
var i=0;
var cnto=0,cnte=0;
while(i<n) {
    if(num[i]%2==1)
        cnto=cnto+1;
    else
        cnte=cnte+1;
    i++;
}
var ans=0;
if(cnto<cnte)
    ans=cnto;
else
    ans=cnte+(cnto-cnte)/3;
print(ans);

var n = readline();
var arr = readline().split();

var nc = 0;

for(var i = 0; i < n; i++){
    nc += (arr[i] % 2 == 1);
}

var c = n - nc;
var t = nc - c;
if (t <= 0)
{
    print(nc);
}
else
{
    print(c + Math.floor(t / 3));
}

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}

var ans = Math.min(num0s,num1s);
num1s -= ans;
ans += Math.floor(num1s/2);
print(ans);

var a = [];
var n = readline();
a = readline().split(" ");
var num0s = 0;
var num1s = 0;
for (var i = 0; i < n; i++) {
    if (a[i] % 2 === 0) {
        num0s++;
    }
    else {
        num1s++;
    }
}
print(Math.min(num0s,num1s));

var a = readline().split(' ');
var b = readline().split(' ');

var odd = 0;
var even = 0;
for(var i = 0; i < a; i++) {
	if(Number(b[i])%2===0)
	{
		even++;
	}else odd ++;

}
var ans = 0;
while(odd>0)
{
	if(even>0)
	{
		even--;
		odd--;
		ans ++;
		continue;
	}
	else{
		if(odd == 1)
		{
			ans--;
			break;
		}
		if(odd == 2)
		{
			break;
		}
		odd-=3;
		ans++;
	}

}
if(ans<0)ans = 0;
print(ans)

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
if(ans>n-ans){
	var tot=ans-(n-ans);
	tot-=tot%3;
	ans+=tot/3;
}
print(ans)

n = readline().split(' ').map(Number);
str = readline().split(' ').map(Number);

var i=0,ans=0;
while(i<n){
	if(str[i]%2==1){
		ans++;
	}
	i++
}
print(ans)

n=readline();
//print(n);
x=readline().split(' ');
imp=0;
pai=0;
for (i = 0; i < n; i++) {
    imp+=(x[i]%2)?1:0;
    pai+=(1-x[i]%2)?1:0;
}
print(Math.min(imp,pai));

var n = Number(readline());
var bouquets = readline().split(' ').map(function(x) { return Number(x)})

var odd = 0, even = 0;
bouquets.forEach(flour => {
    if(flour % 2 == 1) odd++;
    else even++;
});

print(Math.min(odd, even));

var n = parseInt(readline());
var v = readline().split(' ').map(function (x) { return parseInt(x); });

var p = 0
var np = 0

for(var i = 0; i < n; ++i) {
    if(v[i] % 2 === 0) {
        ++p
    } else {
        ++np
    }
}

var ans = p
if(ans > np) {
    ans = np
}

print(ans)

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
    //  print(arr[i] + " ");
	if(arr[i] & 1)	odd++;
	else even++;
}
//print(n + "\n");
if(odd > even){
      var ans = even + (odd - even) / 2;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}

if(odd > even){
      odd -= even;
      var ans = even + odd / 3;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
	if(arr[i] & 1)	odd++;
	else even++;
}
if(odd > even){
	odd -= even;
	var ans = even + odd / 2;
	print(ans);
}else	print(odd);

var n = readline();
var odd = 0 ,even = 0;
var arr = readline().split(" ").map(v => +v.trim());
for(var i = 0 ; i < n ; i++){
    //  print(arr[i] + " ");
	if(arr[i] & 1)	odd++;
	else even++;
}
//print(n + "\n");
if(odd > even){
      var ans = even + (odd - even) / 3;
	print(ans);
}else	print(odd);

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += (odd/3);
	if (x===1 && ans !==0)ans --;

}
print(ans)

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);
	if (x==1 && ans !==0)ans --;

}
print(ans)

// your code goes here
var n = parseInt(readline());
var arr = readline().split(' ');
var odd =0;
var even=0;
for (var i =0;i<n;++i){
	odd+=(parseInt(arr[i])%2)!==0;
	even+=(parseInt(arr[i])%2)===0;
}
var ans =0;
if (even >= odd){
	ans = odd;
}
else {
	ans = even ;
	odd -=even;
	var x  = odd %3;
	ans += Math.floor(odd/3);
	if (x===1 && ans !==0)ans --;

}
print(ans)

var n = readline();
var arr = readline().split(" ");

var o = 0;
var e = 0;
for(var i = 0 ; i < n ; i++) {
    if(arr[i] % 2 === 0) {
        e++;
    }
    else {
        o++;
    }
}

var ans = 0;
    if(o <= e) {
        ans = o;
    }
    else {
        ans = e;
        anss = ans + (o - e) / 3;
    }

    print(ans);

var n = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);
var a = 0;

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	ans += (a - b)/3;
	print(ans);
}

var n = readline().split(' ').map(Number);
var arr = readline().split(' ').map(Number);
var a = 0;

for (var i = 1; i <= n; i++){
   var x = arr[i - 1];
   if(x % 2 == 1)a += 1;
}
var b = n - a;

if(a <= b)print(a);
else {
	var ans = b;
	ans += (a - b) - (a - b)%3;
	print(ans);
}

var n = parseInt(readline());
var a = readline().split(" ");

var i = 0;
var odd = 0;
for (; i < n; ++i)
  if (parseInt(a[i]) % 2 != 0)
    ++odd;

var even = n - odd;
if (even >= odd)
  print(odd);
else
  print(even + (odd - even) / 3);


const nextString = (function() {
  const listeners = [], strings = [], ps = process.stdin
  let last = ''
  ps.setEncoding('utf8')
  ps.on('readable', () => {
    let chunk
    while ((chunk = ps.read()) !== null) {
      chunk = (last + chunk).split(/\r\n|\r|\n/)
      last = chunk[chunk.length - 1]
      for (let i = 0; i < chunk.length - 1; ++i) {
        if (chunk[i].length > 0) {
          if (listeners.length > 0) {
            listeners.shift()(chunk[i])
          }
          else {
            strings.push(chunk[i])
          }
        }
      }
    }
  })
  const fn = resolve => {
    if (strings.length > 0) {
      resolve(strings.shift())
    }
    else {
      listeners.push(resolve)
    }
  }
  return () => new Promise(fn)
})()

function extend(mas) {
  let n = mas.length
  mas.unshift(new Array(n++).fill('.'))
  for (let i = 0; i < n; ++i) {
    mas[i].push('.')
  }
}

async function main() {
  let n = +await nextString()
  if (n === 2) {
    console.log('-1')
    return
  }
  let m = n % 2 === 0 ? 2 : 1
  while (((m + 2) ** 2) <= n && ((n - ((m + 2) ** 2)) % 2) === 0) {
    m += 2
  }
  let mas = new Array(m)
    .fill(42)
    .map(() => new Array(m).fill('o'))
  let f = m
  n -= m * m;
  while (n > 0) {
    extend(mas)
    ++m
    for (let i = 0; i < f && n > 0; ++i, n -= 2) {
      mas[0][i] = mas[m - 1 - i][m - 1] = 'o'
    }
  }
  let str = mas.map(row => row.join('')).join('\n')
  console.log(m + '\n' + str)
}

main()

let _DEBUG;

const fs = require('fs');
const { assert } = require('console');
const print = console.log;
const debug = (x) => {
    if (!_DEBUG) return;
    let vn = Object.keys(x)[0];
    console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

const MAXN = 100;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

if (n == 2) {
    print(-1);
} else {
    let m = n % 2;
    while ((m + 2) * (m + 2) <= n) {
        m += 2;
    }

    let rem = n - m * m;
    assert(rem % 2 == 0);
    let hrem = rem / 2;

    let h = Math.ceil(hrem / m);
    let s = m + h;

    debug({ n });
    debug({ m });

    print(s);
    let r = [];
    for (let i = 0; i < s; i++) {
        r.push('.'.repeat(s).split(''));
    }
    for (let i = 0; i < m; i++) {
        for (let j = 0; j <= i; j++) {
            r[i][j] = r[j][i] = 'o';
        }
    }
    for (let i = m; i < m + h; i++) {
        for (let j = 0; j < m; j++) {
            let t = (hrem - 1) % m + 1;
            if (i < m + h - 1 || j < t) {
                r[i][j] = r[j][i] = ['o'];
            }
        }
    }

    print(
        r
            .reverse()
            .map((x) => x.join(''))
            .join('\n')
    );
}

n = +readline()

if (n%2===0) {
    bd = n/2
} else {
    bd = (n+1)/2
}

function solve(){
    for (var len = 1;len<=bd;len++)
    {
        for (var sq = 1;sq<=len;sq++)
        {
            var now = len*2-1 + (sq-1)*(sq-1)
            var add = (sq-1) * (len-sq) * 2
            if (now <= n && n <= now+add && now%2 == n%2) {
                print(len)
                S = '.'.repeat(len)
                ans = []
                for (var z=0;z<len;z++){
                    ans.push(S)
                }

                for (var i=0;i<len;i++)
                {
                    for (var j=0;j<len;j++)
                    {
                        if (i==0 || j==0 || (i<sq && j<sq)) {
                            ans[i] = ans[i].replace('.','o')
                        }
                    }
                }

                for (var i = sq; i<len && now<n; i++)
                {
                    for (var j = 1;j<sq && now<n; j++)
                    {
                        ans[i] = ans[i].replace('.','o')
                        ans[j] = ans[j].replace('.','o')
                        now += 2
                    }
                }
                for (var i=len-1;i>=0;i--)
                {
                    print(ans[i])
                }
                return
            }
        }
    }
}

if (n==2)
    print(-1)
else
    solve()

let _DEBUG;

const fs = require('fs');
const { assert } = require('console');
const print = console.log;
const debug = (x) => {
    if (!_DEBUG) return;
    let vn = Object.keys(x)[0];
    console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

const MAXN = 100;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

if (n == 2) {
    print(-1);
} else {
    let m = n % 2;
    while ((m + 2) * (m + 2) <= n) {
        m += 2;
    }

    let rem = n - m * m;
    assert(rem % 2 == 0);
    let hrem = rem / 2;

    let h = Math.ceil(hrem / m);
    let s = m + h;

    debug({ n });
    debug({ m });

    print(s);
    let r = [];
    for (let i = 0; i < s; i++) {
        r.push('.'.repeat(s).split(''));
    }
    for (let i = 0; i < m; i++) {
        for (let j = 0; j <= i; j++) {
            r[i][j] = r[j][i] = 'o';
        }
    }
    for (let i = m; i < m + h; i++) {
        for (let j = 0; j < m; j++) {
            let t = (hrem - 1) % m + 1;
            if (i < m || j < t) {
                r[i][j] = r[j][i] = ['o'];
            }
        }
    }

    print(
        r
            .reverse()
            .map((x) => x.join(''))
            .join('\n')
    );
}

let _DEBUG = 1;

const fs = require('fs');
const print = console.log;
const debug = (x) => {
  if (!_DEBUG) return;
  let vn = Object.keys(x)[0];
  console.error(`${vn}: ${x[vn]}`);
};
const debugf = !_DEBUG ? () => {} : console.error;

let input = fs.readFileSync(0).toString();
input = input.split(/\r?\n/g);

let n = +input[0];

let s = 1;
while (s * s < n) {
    s++;
}

let r = [];
for (let i = 0; i < s; i++) {
    r.push('.'.repeat(s).split(''));
}

r[s - 1][0] = ['o'];
let t = n - (s - 1) * (s - 1);

for (let i = 0; i < s - 1; i++) {
    for (let j = 0; j < s - 1; j++) {
        r[s - 1 - i][j] = ['o'];
    }
}

for (let i = 0; i < s && t >= 2; i++) {
    r[0][i] = ['o'];
    r[s - 1 - i][s - 1] = ['o'];
    t -= 2;
}

if (n == s * s) {
    r[0][s - 1] = ['o'];
    t = 0;
}

if (t == 0) {
    print(s);
    print(r.map(x => x.join('')).join('\n'));
} else {
    print(-1);
}