// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

import std.container;
import std.stdio;
import std.conv;

void main() {
  int t;
  readf("%s\n", &t);

  while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);
    auto rbt = new RedBlackTree!(string);

    for(int k = 1; k <= 3; ++k)
      for(int i = 0; i <= n-k; ++i)
        rbt.insert(s[i..i+k]);

    string abc = "abcdefghijklmnopqrstuvwxyz";
    auto q = DList!string();
    for(char c = 'a'; c <= 'z'; ++c) {
      q.insert(c.to!string);
    }

    while(!q.empty) {
      auto p = q.front();
      q.removeFront();
      if(!(p in rbt)) {
        p.writeln;
        break;
      }
      foreach(char l; abc)
        q.insertBack(p ~ l);
    }
  }
}

// Cheese-Cracker: cheese-cracker.github.io

dchar[] getStr(ll num){
    dchar[] res;
    while(num > 0){
        num -= 1;
        ll cr = (num % 26);
        if(cr >= 0){
            res ~= to!dchar(cr + 'a');
        }
        num /= 26;
    }
    res.reverse;
    return res;
}

int makeNum(dchar[] w, int st, int end){
    int res = 0;
    for(int i = st; i <= end; ++i){
        dchar cr = w[i];
        res *= 26;
        res += (cr - 'a' +  1);
    }
    return res;
}

void theCode(){
    ll n = scan;
    auto word = scan!(dchar[]);
    auto freq = new ll[](2000);
    for(int j = 0; j < 3; ++j){
        for(int i = 0; i < n - j; ++i){
            int num = makeNum(word, i, i+j);
            if(num < 2000){
                ++freq[num];
            }
        }
    }
    for(int i = 1; i < 2000; ++i){
        if(!freq[i]){
            writeln(getStr(i));
            return;
        }
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) theCode();
}

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(!canFind(s, item)) {
            item.writeln;
            break;
        }
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(canFind(s, item))
            continue;
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

    int n;
    string s;
while(t--) {
    readf("%s\n", &n);
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'e'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length == b.length)
        return a < b;
    return a.length < b.length;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi,false);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    bool[] three = new bool[](26 * 26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
      if (i + 2 < s.length)
        three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    long x3 = three.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    auto result3 = ['a', 'a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else if (x2 < 26 * 26) {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    } else {
      result3[0] += x3 / (26 * 26);
      result3[1] += (x3 / 26) % 26;
      result3[2] += x3 % 26;
      writefln("%s", result3.idup);
    }
  }
}

import std.container;
import std.stdio;
import std.conv;

void main() {
  int t;
  readf("%s\n", &t);

  while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);
    auto rbt = new RedBlackTree!string;

    for(int k = 1; k <= 3; ++k)
      for(int i = 0; i <= n-k; ++i)
        rbt.insert(s[i..i+k]);

    string abc = "abcdefghijklmnopqrstuvwxyz";
    auto q = DList!string();
    for(char c = 'a'; c <= 'z'; ++c) {
      q.insert(c.to!string);
    }

    while(!q.empty) {
      auto p = q.front();
      q.removeFront();
      if(!(p in rbt)) {
        p.writeln;
        break;
      }
      foreach(char l; abc)
        q.insertBack(p ~ l);
    }
  }
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            /*
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
            */
        }
    }

    rbtree.insert("aaa");

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    else if(a.length == b.length)
        return a < b;
    else
        return false;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
            /*
            for(char e = 'a'; e <= 'z'; ++e) {
                string three = [c, d, e];
                rbtree.insert(three);
            }
            */
        }
    }

    rbtree.insert("aaa");
    rbtree.writeln;

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
        }
    }
    rbtree.insert("aaa");

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

// Vicfred
// https://codeforces.com/contest/1536/problem/B
// brute force, constructive
import std.algorithm;
import std.container;
import std.conv;
import std.functional;
import std.stdio;

bool lexi(string a, string b) {
    if(a.length < b.length)
        return true;
    return a < b;
}

void main() {
    auto rbtree = new RedBlackTree!(string,lexi);
    for(char c = 'a'; c <= 'z'; ++c) {
        string one = [c];
        rbtree.insert(one);
        for(char d = 'a'; d <= 'z'; ++d) {
            string two = [c, d];
            rbtree.insert(two);
        }
    }

    int t;
    readf("%s\n", &t);

while(t--) {
    int n;
    readf("%s\n", &n);
    string s;
    readf("%s\n", &s);

    foreach(item; rbtree) {
        if(count(s, item) > 0) {
            continue;
        }
        item.writeln;
        break;
    }
}
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    bool[] three = new bool[](26 * 26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
      if (i + 2 < s.length)
        three[(s[i] - 'a') * 26 * 26 + (s[i + 1] - 'a') * 26 + (s[i + 2] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    long x3 = three.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    auto result3 = ['a', 'a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else if (x2 < 26 * 26) {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    } else {
      result3[0] += x2 / (26 * 26);
      result3[1] += (x2 / 26) % 26;
      result3[2] += x2 % 26;
      writefln("%s", result3.idup);
    }
  }
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26 + 1);
    bool[] two = new bool[](26 * 26 + 1);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < 26) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    }
  }
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1.idup);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.idup);
    }
  }
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1.to!string);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2.to!string);
    }
  }
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    auto result1 = ['a'];
    auto result2 = ['a', 'a'];
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2);
    }
  }
}

import std.stdio, std.algorithm, std.conv, std.string, std.array, std.random;

void main()
{
  int t;
  readf!" %d "(t);
  foreach (casenum ; 0 .. t) {
    int n;
    readf!" %d "(n);
    auto s = readln.strip;
    bool[] one = new bool[](26);
    bool[] two = new bool[](26 * 26);
    foreach (i ; 0 .. s.length) {
      one[s[i] - 'a'] = true;
      if (i + 1 < s.length)
        two[(s[i] - 'a') * 26 + (s[i + 1] - 'a')] = true;
    }
    long x1 = one.countUntil(false);
    long x2 = two.countUntil(false);
    char[1] result1 = "a";
    char[2] result2 = "aa";
    if (x1 < one.length) {
      result1[0] += x1;
      writefln("%s", result1);
    } else {
      result2[0] += x2 / 26;
      result2[1] += x2 % 26;
      writefln("%s", result2);
    }
  }
}

// Cheese-Cracker: cheese-cracker.github.io

dchar[] getStr(ll num){
    dchar[] res;
    while(num > 0){
        ll cr = (num % 26) - 1;
        if(cr >= 0){
            res ~= to!dchar(cr + 'a');
        }
        num /= 26;
    }
    res.reverse;
    return res;
}

int makeNum(dchar[] w, int st, int end){
    int res = 0;
    for(int i = st; i <= end; ++i){
        dchar cr = w[i];
        res *= 26;
        res += (cr - 'a' + 1);
    }
    return res;
}

void theCode(){
    ll n = scan;
    auto word = scan!(dchar[]);
    auto freq = new ll[](2000);
    for(int j = 0; j < 3; ++j){
        for(int i = 0; i < n - j; ++i){
            int num = makeNum(word, i, i+j);
            if(num < 2000){
                ++freq[num];
            }
        }
    }
    for(int i = 1; i < 2000; ++i){
        if(!freq[i]){
            writeln(getStr(i));
            return;
        }
    }
}

void main(){
    long tests = scan;        // Toggle!
    while(tests--) theCode();
}

/*********  That's All Folks!  *********/
import std.stdio, std.random, std.functional, std.container, std.algorithm;
import std.numeric, std.range, std.typecons, std.string, std.math, std.conv;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");


// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops

import std;

void main()
{
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;

    // calculate 'm' and 'M' in a single pass while reading the array
    auto a = readln.splitter.map!((x) { auto k = x.to!int;
                                        if (k > M) {
                                          m = M;
                                          M = k;
                                        } else if (k > m) {
                                          m = k;
                                        }
                                        return k; }).array;

    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Allocate the array on stack. Bring back printf.

import std;

void main()
{
  int[200000] arr = void;
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;
    auto a = arr[0 .. n];

    // calculate 'm' and 'M' in a single pass while reading the array
    readln.splitter.map!((x) { auto k = x.to!int;
                               if (k > M) {
                                 m = M;
                                 M = k;
                               } else if (k > m) {
                                 m = k;
                               }
                               return k; }).copy(a);

    foreach (k ; a)
      printf("%d ", (k == M) ? (k - m) : (k - M));
    printf("\n");
  }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Allocate the array on stack.

import std;

void main()
{
  int[200000] arr = void;
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;
    auto a = arr[0 .. n];

    // calculate 'm' and 'M' in a single pass while reading the array
    readln.splitter.map!((x) { auto k = x.to!int;
                               if (k > M) {
                                 m = M;
                                 M = k;
                               } else if (k > m) {
                                 m = k;
                               }
                               return k; }).copy(a);
    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

import std;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array;
    auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);
    n.iota.map!(i => a[i] - max(seg.prod(0, i), seg.prod(i + 1, n)))
          .writefln!"%(%s %)";
  }
}

// Code from: https://github.com/kotet/atcoder-library-d

int celiPow2(int n) @safe pure nothrow @nogc
{
    int x = 0;
    while ((1u << x) < cast(uint)(n))
        x++;
    return x;
}

// --- segtree ---

struct Segtree(S, alias op, alias e)
{
    import std.functional : binaryFun, unaryFun;
    import std.traits : isCallable, Parameters;

    static if (is(typeof(e) : string))
    {
        auto unit()
        {
            return mixin(e);
        }
    }
    else
    {
        alias unit = e;
    }

    this(int n)
    {
        auto buf = new S[](n);
        buf[] = unit();
        this(buf);
    }

    this(S[] v)
    {
        _n = cast(int) v.length;
        log = celiPow2(_n);
        size = 1 << log;
        d = new S[](2 * size);
        d[] = unit();
        foreach (i; 0 .. _n)
            d[size + i] = v[i];
        foreach_reverse (i; 1 .. size)
            update(i);
    }

    void set(int p, S x)
    {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        foreach (i; 1 .. log + 1)
            update(p >> i);
    }

    S get(int p)
    {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r)
    {
        assert(0 <= l && l <= r && r <= _n);
        S sml = unit(), smr = unit();
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = binaryFun!(op)(sml, d[l++]);
            if (r & 1)
                smr = binaryFun!(op)(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return binaryFun!(op)(sml, smr);
    }

    S allProd()
    {
        return d[1];
    }

    int maxRight(alias f)(int l)
    {
        return maxRight(l, &unaryFun!(f));
    }

    int maxRight(F)(int l, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= l && l <= _n);
        assert(f(unit()));
        if (l == _n)
            return _n;
        l += size;
        S sm = unit();
        do
        {
            while (l % 2 == 0)
                l >>= 1;
            if (!f(binaryFun!(op)(sm, d[l])))
            {
                while (l < size)
                {
                    l = 2 * l;
                    if (f(binaryFun!(op)(sm, d[l])))
                    {
                        sm = binaryFun!(op)(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = binaryFun!(op)(sm, d[l]);
            l++;
        }
        while ((l & -l) != l);
        return _n;
    }

    int minLeft(alias f)(int r)
    {
        return minLeft(r, &unaryFun!(f));
    }

    int minLeft(F)(int r, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= r && r <= _n);
        assert(f(unit()));
        if (r == 0)
            return 0;
        r += size;
        S sm = unit();
        do
        {
            r--;
            while (r > 1 && (r % 2))
                r >>= 1;
            if (!f(binaryFun!(op)(d[r], sm)))
            {
                while (r < size)
                {
                    r = 2 * r + 1;
                    if (f(binaryFun!(op)(d[r], sm)))
                    {
                        sm = binaryFun!(op)(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = binaryFun!(op)(d[r], sm);
        }
        while ((r & -r) != r);
        return 0;
    }

private:
    int _n = 0, size = 1, log = 0;
    S[] d = [unit(), unit()];
    void update(int k)
    {
        d[k] = binaryFun!(op)(d[2 * k], d[2 * k + 1]);
    }
}

// Taken from https://codeforces.com/contest/1760/submission/182072909
// and rewritten a bit to get rid of C/C++ style scanf/printf and
// imperative loops. Also added ".take(n)"

import std;

void main()
{
  foreach (t ; readln.strip.to!int.iota) {
    int m = 0, M = 0, n = readln.strip.to!int;

    // calculate 'm' and 'M' in a single pass while reading the array
    auto a = readln.splitter.map!((x) { auto k = x.to!int;
                                        if (k > M) {
                                          m = M;
                                          M = k;
                                        } else if (k > m) {
                                          m = k;
                                        }
                                        return k; }).take(n).array;

    a.map!(k => (k == M) ? (k - m) : (k - M)).writefln!"%(%s %)";
  }
}

import std;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    auto n = readln.strip.to!int;
    auto a = readln.splitter.map!(to!int).array;
    auto seg = a.Segtree!(int, (x, y) => max(x, y), () => 0);
    int[] ans;
    foreach (i ; 0 .. a.length.to!int) {
      int best = max(seg.prod(0, i), seg.prod(i + 1, n));
      ans ~= a[i] - best;
    }
    writefln("%(%s %)", ans);
  }
}

// Code from: https://github.com/kotet/atcoder-library-d

int celiPow2(int n) @safe pure nothrow @nogc
{
    int x = 0;
    while ((1u << x) < cast(uint)(n))
        x++;
    return x;
}

// --- segtree ---

struct Segtree(S, alias op, alias e)
{
    import std.functional : binaryFun, unaryFun;
    import std.traits : isCallable, Parameters;

    static if (is(typeof(e) : string))
    {
        auto unit()
        {
            return mixin(e);
        }
    }
    else
    {
        alias unit = e;
    }

    this(int n)
    {
        auto buf = new S[](n);
        buf[] = unit();
        this(buf);
    }

    this(S[] v)
    {
        _n = cast(int) v.length;
        log = celiPow2(_n);
        size = 1 << log;
        d = new S[](2 * size);
        d[] = unit();
        foreach (i; 0 .. _n)
            d[size + i] = v[i];
        foreach_reverse (i; 1 .. size)
            update(i);
    }

    void set(int p, S x)
    {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        foreach (i; 1 .. log + 1)
            update(p >> i);
    }

    S get(int p)
    {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r)
    {
        assert(0 <= l && l <= r && r <= _n);
        S sml = unit(), smr = unit();
        l += size;
        r += size;
        while (l < r)
        {
            if (l & 1)
                sml = binaryFun!(op)(sml, d[l++]);
            if (r & 1)
                smr = binaryFun!(op)(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return binaryFun!(op)(sml, smr);
    }

    S allProd()
    {
        return d[1];
    }

    int maxRight(alias f)(int l)
    {
        return maxRight(l, &unaryFun!(f));
    }

    int maxRight(F)(int l, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= l && l <= _n);
        assert(f(unit()));
        if (l == _n)
            return _n;
        l += size;
        S sm = unit();
        do
        {
            while (l % 2 == 0)
                l >>= 1;
            if (!f(binaryFun!(op)(sm, d[l])))
            {
                while (l < size)
                {
                    l = 2 * l;
                    if (f(binaryFun!(op)(sm, d[l])))
                    {
                        sm = binaryFun!(op)(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = binaryFun!(op)(sm, d[l]);
            l++;
        }
        while ((l & -l) != l);
        return _n;
    }

    int minLeft(alias f)(int r)
    {
        return minLeft(r, &unaryFun!(f));
    }

    int minLeft(F)(int r, F f) if (isCallable!F && Parameters!(F).length == 1)
    {
        assert(0 <= r && r <= _n);
        assert(f(unit()));
        if (r == 0)
            return 0;
        r += size;
        S sm = unit();
        do
        {
            r--;
            while (r > 1 && (r % 2))
                r >>= 1;
            if (!f(binaryFun!(op)(d[r], sm)))
            {
                while (r < size)
                {
                    r = 2 * r + 1;
                    if (f(binaryFun!(op)(d[r], sm)))
                    {
                        sm = binaryFun!(op)(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = binaryFun!(op)(d[r], sm);
        }
        while ((r & -r) != r);
        return 0;
    }

private:
    int _n = 0, size = 1, log = 0;
    S[] d = [unit(), unit()];
    void update(int k)
    {
        d[k] = binaryFun!(op)(d[2 * k], d[2 * k + 1]);
    }
}

import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
//import std.numeric;
//import std.range;
import std.array;
//import std.bigint;
import std.string;

void sol(){

    int n, k, m=0, M=0;
    int[200000] arr;

    scanf("%d",&n);

    foreach(i; 0..n){
        scanf("%d ",&k);
        arr[i] = k;

        if(k>M){
            m=M;
            M=k;
        }
        else if(k>m){
            m=k;
        }
    }

    foreach(i; 0..n){
        k = arr[i];
        if (k==M){
            printf("%d ", k-m);
        }
        else{
            printf("%d ", k-M);
        }
    }
    printf("\n");
}

void main(){

    int t;
    readf!"%d"(t);
    while (t--){
        sol();
    }
}

import std.stdio, std.conv, std.string, std.algorithm, std.array;

void main()
{
    auto t = readln().strip().to!int;
    foreach (_; 0..t)
    {
        auto n = readln().strip().to!int;
        auto s = readln().strip().split().map!(e=>e.to!int).array;
        auto sorted = s.dup;
        sorted.sort;

        foreach (e; s)
        {
            if (e == sorted[$-1])
            {
                writef("%d ", e - sorted[$-2]);
            }
            else
            {
                writef("%d ", e - sorted[$-1]);
            }
        }
    }
}

import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
//import std.numeric;
//import std.range;
import std.array;
//import std.bigint;
import std.string;

void sol(){

    int n, k, m=0, M=0;
    int[200000] arr;

    scanf("%d",&n);

    foreach(i; 0..n){
        scanf("%d ",&k);
        arr[i] = k;

        if(k>M){
            M=k;
        }
        else if(k>m){
            m=k;
        }
    }

    foreach(i; 0..n){
        k = arr[i];
        if (k==M){
            printf("%d ", k-m);
        }
        else{
            printf("%d ", k-M);
        }
    }
    printf("\n");
}

void main(){

    int t;
    readf!"%d"(t);
    while (t--){
        sol();
    }
}


import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	long n = read.to!long;
	long m = read.to!long;

	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i, 0);

	foreach(nd; nodes){
		nd.group = new Group(nd);
	}

	Edge[] edges;
	foreach(i; 0 .. m){
		long k = read.to!long;
		if(k > 0){
			int a = read.to!int - 1;
			foreach(j; 1 .. k){
				int b = read.to!int - 1;
				edges ~= new Edge(nodes[a], nodes[b], 1);
			}
		}
	}

	foreach(ed; edges){
		if(ed.node1.group.id != ed.node2.group.id){
			ed.node1.group.eat(ed.node2.group);
		}
	}

	long[] ans;
	foreach(nd; nodes) ans ~= nd.group.nodes.length;

	ans.map!(to!string).join(" ").writeln;

}

class Edge{
	Node node1;
	Node node2;
	long value;
	this(Node node1, Node node2, long value){
		this.node1 = node1, this.node2 = node2;
		this.value = value;
	}
}

class Node{
	long id;
	long value;
	Group group;
	this(long id, long value){
		this.id = id;
		this.value = value;
	}
}

class Group{
	long value;
	long pendingEdgeCount;
	long id;
	Node[] nodes;
	this(Node node){
		this.id = node.id;
		this.nodes = [node];
		this.value = node.value;
	}
	void eat(Group gp){
		if(gp.nodes.length > this.nodes.length) gp.eat(this);
		else{
			foreach(nd; gp.nodes){
				this.nodes ~= nd;
				nd.group = this;
				this.value += nd.value;
			}
			this.pendingEdgeCount += gp.pendingEdgeCount;
		}
	}
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.random;
import std.datetime.systime : Clock;

class DisjointSet {
  private:
    int [] p, h;
    int n;
  public:
  this (int _n) {
    n = _n;
    p = iota (0, n).array;
    h = new int[n];
  }
  int findSet (int x) pure nothrow @nogc {
    if (p[x] == x) {
      return x;
    }
    return p[x] = findSet (p[x]);
  }
  void merge (int i, int j) pure nothrow @nogc {
    i = findSet (i);
    j = findSet (j);
    if (i != j) {
      if (h[i] < h[j]) {
        p[i] = j;
      } else if (h[i] > h[j]) {
        p[j] = i;
      } else {
        p[i] = j;
        ++h[j];
      }
    }
  }
  int biggest_set_size () pure {
    auto c = new int[n];
    foreach (i; 0 .. n) {
      ++c[findSet (i)];
    }
    return c.reduce! (max);
  }
}

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader;
  immutable n = r.next!uint, m = r.next!uint;
  auto ds = new DisjointSet (n);
  foreach (group; 0 .. m) {
    immutable k = r.next!uint;
    auto x = r.nextA!uint (k);
    foreach (i; 1 .. k) {
      ds.merge (x[i] - 1, x[i-1] - 1);
    }
  }
  auto c = new int[n];
  foreach (i; 0 .. n) {
    ++c[ds.findSet (i)];
  }
  int[] res;
  res.reserve (n);
  foreach (i; 0 .. n) {
    res ~= c[ds.findSet (i)];
  }
  writefln ("%(%s %)", res);
}

module _;
void main() {
	import std.stdio;
	import std.algorithm;
	import std.array, std.range;
	int n,m;
	int[] pa, h, sz;
	readf("%s %s ", &n, &m);
	pa = iota(n).array;
	h = new int[n];
	sz = new int[n];
	h[] = 1;
	sz[] = 1;

	int getpa(int a) {
		if (pa[a] == a) {
			return a;
		}
		pa[a] = getpa(pa[a]);
		return pa[a];
	}
	void merge(int a, int b) {
		int paa = getpa(a), pab = getpa(b);
		if (paa == pab) {
			return;
		}
		if (h[paa] > h[pab]) {
			pa[pab] = paa;
			sz[paa] += sz[pab];
		} else {
			pa[paa] = pab;
			sz[pab] += sz[paa];
			if (h[paa] == h[pab]) {
				h[pab]++;
			}
		}
	}

	foreach(i; 0..m) {
		int k;
		readf("%s ", &k);
		if (k) {
			int mem0;
			readf("%s ", &mem0);
			foreach(j; 1..k) {
				int mem;
				readf("%s ", &mem);
				merge(mem-1, mem0-1);
			}
		}
	}
	foreach(i; 0..n) {
		writef("%s ", sz[getpa(i)]);
	}
	writeln;
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto uf = new UnionFind(N);
    foreach (_; 0..M) {
        auto A = readln.split.map!(to!int).array;
        foreach (i; 2..A.length.to!int) {
            uf.unite(A[1]-1, A[i]-1);
        }
    }
    N.iota.map!(i => -uf.table[uf.find(i)]).map!(to!string).join(" ").writeln;
}

class UnionFind {
    int N;
    int[] table;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        table[y] = x;
    }
}

module _;
void main() {
	import std.stdio;
	import std.algorithm;
	import std.array, std.range;
	int n,m;
	int[] pa, h, sz;
	readf("%s %s ", &n, &m);
	pa = iota(n).array;
	h = new int[n];
	sz = new int[n];
	h[] = 1;
	sz[] = 1;

	int getpa(int a) {
		if (pa[a] == a) {
			return a;
		}
		pa[a] = getpa(pa[a]);
		return pa[a];
	}
	void merge(int a, int b) {
		int paa = getpa(a), pab = getpa(b);
		if (h[paa] > h[pab]) {
			pa[pab] = paa;
			sz[paa] += sz[pab];
		} else {
			pa[paa] = pab;
			sz[pab] += sz[paa];
			if (h[paa] == h[pab]) {
				h[pab]++;
			}
		}
	}

	foreach(i; 0..m) {
		int k;
		readf("%s ", &k);
		int mem0;
		if (k) {
			readf("%s ", &mem0);
			foreach(j; 1..k) {
				int mem;
				readf("%s ", &mem);
				merge(mem-1, mem0-1);
			}
		}
	}
	foreach(i; 0..n) {
		writef("%s ", sz[getpa(i)]);
	}
	writeln;
}


// Vicfred
// https://codeforces.com/contest/1421/problem/A
//
import std.stdio;

void main() {
    long t;
    readf("%s\n", &t);

    long a, b;
    while(t--) {
        readf("%s %s\n", &a, &b);

        long bits = 0L;

        for(int i = 0; i < 32; i++)
            if(a&(1<<i) && b&(1<<i))
                bits += (1<<i);

        long ans = (a^bits) + (b^bits);
        ans.writeln;
    }
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto a = RD!int;
		auto b = RD!int;

		auto x = a & b;
		ans[ti] = (a ^ x) + (b ^ x);
	}

	foreach (e; ans)
	{
		writeln(e);
	}
	stdout.flush;
	debug readln;
}


import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    int h1, a1, c1;
    int h2, a2;

    scan(h1, a1, c1);
    scan(h2, a2);

    auto cmd = ["STRIKE", "HEAL"];

    auto ans = new string[](0);

    while (h2 > 0) {
        if (h2 > a1 && h1 <= a2) {
            ans ~= cmd[1];
            h1 += c1;
        }
        else {
            ans ~= cmd[0];
            h2 -= a1;
        }

        h1 -= a2;
    }

    writeln(ans.length);
    foreach (ai ; ans) {
        writeln(ai);
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,
	std.container, std.conv, std.datetime, std.functional, std.math, std.meta;
import std.numeric : Fft, fft, gcd, inverseFft;
import std.parallelism, std.random, std.range, std.regex, std.stdio, std.string,
	std.traits, std.typecons, std.uni, std.variant;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
// alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
/// struct vector as c++ vector
struct Vec(T)
{
	private Array!T buf;
	alias buf this;
	this(this)
	{
		buf = buf.dup;
	}
	/// construct from length
	this(U)(U length)
			if (is(U == int) || is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint))
	{
		buf.length = length;
	}
	/// construct from length and default value
	this(U, X)(U length, X val)
			if (isImplicitlyConvertible!(X, T) || (is(U == int)
				|| is(U == size_t) || is(U == long) || is(U == ulong) || is(U == uint)))
	{
		buf.length = length;
		foreach (ref x; buf[])
		{
			x = val;
		}
	}
	/// construct from other array
	this(U)(U[] values...) if (isImplicitlyConvertible!(U, T))
	{
		buf = Array!(T)(values);
	}
	/// construct from other range
	this(Range)(Range r)
			if (isInputRange!Range && isImplicitlyConvertible!(ElementType!Range,
				T) && !is(Range == T[]))
	{
		buf = Array!(T)(r);
	}
	/// integer length
	int size() @property const
	{
		return cast(int) buf.length;
	}
}
///mmulo
enum mm = 10 ^^ 9 + 7, mm2 = mm + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt biggcd(BigInt a, BigInt b)
		{
			BigInt res = 1;
			while (b)
			{
				if ((a & 1) && (b & 1))
				{
					a -= b;
					a >>= 1;
				}
				else if (a & 1)
				{
					b >>= 1;
				}
				else if (b & 1)
				{
					a >>= 1;
				}
				else
				{
					res <<= 1;
					a >>= 1;
					b >>= 1;
				}
				if (a < b)
					swap(a, b);
			}
			return res * a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///posicion lower bound
		size_t lowb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).lowerBound(g).length;
		}
		///posicion upper bound
		size_t upb(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return a.length - assumeSorted(a).upperBound(g).length;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return assumeSorted(a).contains(g);
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}
	///read without format
	bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		return readf!(replicate(" %s", ptrs.length))(ptrs) == ptrs.length;
	}
	///readln without format
	bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
	{
		return readf!(replicate(" %s", ptrs.length) ~ '\n')(ptrs) == ptrs.length;
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	int h1, a1, c1;
	read(h1, a1, c1);
	int h2, a2;
	read(h2, a2);
	string[] ans;
	while (h2 > 0)
	{
		if (a1 >= h2)
		{
			ans ~= "STRIKE";
			break;
		}
		else if (a2 >= h1)
		{
			ans ~= "HEAL";
			h1 += c1;
		}
		else
		{
			ans ~= "STRIKE";
			h2 -= a1;
		}
		h1 -= a2;
	}
	writeln(ans.length);
	foreach (s; ans)
	{
		writeln(s);
	}
}


void main() { runSolver(); }

void problem() {
  auto QN = scan!int;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto A = scan!int(N);

      int lastOdd = 1;
      int lastEven = 0;
      foreach(a; A) {
        if (a % 2 == 0) {
          if (lastOdd > a) return YESNO[false];
          lastOdd = a;
        } else {
          if (lastEven > a) return YESNO[false];
          lastEven = a;
        }
      }

      return YESNO[true];
    }

    foreach(i; 0..QN) {
      subSolve().writeln;
    }
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std.stdio, std.string, std.conv;
import std.algorithm.iteration;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.typecons;
void solution(ref File input, ref File output) {
    auto t = input.readln.chomp.to!int;
    while (t-- > 0) {
        auto _ = input.readln;
        auto source = input.readln.chomp
            .split(' ')
            .map!(to!int);
        int max_e = -1, max_o = -1;
        foreach(item; source)
        {
            if (item % 2) {
                if (max_o > item)
                {
                    output.writeln("No");
                    goto end;
                } else
                {
                    max_o = item;
                }

            } else
            {
                if (max_e > item)
                {
                    output.writeln("No");
                    goto end;
                } else
                {
                    max_e = item;
                }

            }
        }
        output.writeln("Yes");
        end:
    }
}
void main()
{
    File input, output;
    debug(1) {
        input = File("input.txt", "r");
        output = File("output.txt", "w");
    } else {
        input = stdin;
        output = stdout;
    }
    solution(input, output);
}

import std.stdio, std.string, std.conv;
import std.algorithm.iteration;
import std.algorithm.searching;
import std.algorithm.mutation;
import std.range;
import std.typecons;
void solution(ref File input, ref File output) {
    auto t = input.readln.chomp.to!int;
    while (t-- > 0) {
        auto _ = input.readln;
        auto source = input.readln.chomp
            .split(' ')
            .map!(to!int);
        int max_e = -1, max_o = -1;
        foreach(item; source)
        {
            if (item % 2) {
                if (max_o > item)
                {
                    output.writeln("No");
                    goto end;
                }
                if (max_o == -1)
                {
                    max_o = item;
                }

            } else
            {
                if (max_e > item)
                {
                    output.writeln("No");
                    goto end;
                }
                if (max_e == -1)
                {
                    max_e = item;
                }

            }
        }
        output.writeln("Yes");
        end:
    }
}
void main()
{
    File input, output;
    debug(1) {
        input = File("input.txt", "r");
        output = File("output.txt", "w");
    } else {
        input = stdin;
        output = stdout;
    }
    solution(input, output);
}


import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto t = RD!int;
	auto ans = new int[](t);
	foreach (ti; 0..t)
	{
		auto abc = RDA;
		abc.sort!"a > b"();
		foreach (ref e; abc)
		{
			if (e != 0)
			{
				++ans[ti];
				--e;
			}
		}
		foreach (i; 0..2)
		{
			foreach (j; i+1..3)
			{
				if (abc[i] != 0 && abc[j] != 0)
				{
					++ans[ti];
					--abc[i];
					--abc[j];
				}
			}
		}
		if (abc[0] != 0 && abc[1] != 0 && abc[2] != 0)
			++ans[ti];
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}

module main;

import std.stdio : writeln;

struct IO {
    string readToken() {
        import std.range : empty, front, popFront, split;
        import std.stdio : readln;

        while (tokens.empty) {
            tokens = readln.split;
        }
        auto token = tokens.front;
        tokens.popFront;
        return token;
    }

    int readInt() {
        import std.conv : to;

        return readToken.to!int;
    }

    string[] tokens;
}

void main() {
    import core.bitop : popcnt;
    import std.algorithm : max;

    IO io;
    int T = io.readInt;
    while (T--) {
        int[3] count;
        for (int i = 0; i < 3; ++i) {
            count[i] = io.readInt;
        }
        int result = 0;
        for (int mask = 0; mask < 1 << 8; mask += 2) {
            bool ok = true;
            for (int i = 0; i < 3; ++i) {
                int c = count[i];
                for (int s = 0; s < 8; ++s) {
                    if ((s >> i & 1) && (mask >> s & 1)) {
                        c--;
                    }
                }
                ok &= c >= 0;
            }
            if (ok) {
                result = max(result, popcnt(mask));
            }
        }
        writeln(result);
    }
}

import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

void main() {
    int t;
    scan(t);

    while (t--) {
        int a, b, c;
        scan(a, b, c);
        auto ans = solve(a, b, c);
        writeln(ans);
    }
}

int solve(int a, int b, int c) {
    int res;

    foreach (comb ; 0 .. 1 << (1 << 3)) {
        auto x = new int[](3);

        foreach (i ; 0 .. 1 << 3) if (comb & 1 << i) {
            foreach (j ; 0 .. 3) if (i & 1 << j) {
                x[j]++;
            }
        }

        if (x[0] <= a && x[1] <= b && x[2] <= c) {
            chmax(res, comb.popcnt);
        }
    }

    res--;

    return res;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


// a
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

void main() {
  try {
    for (; ; ) {
      const numCases = readInt();
      foreach (caseId; 0 .. numCases) {
        const A = readLong();
        const B = readLong();

        long ans = 1;
        if (A % B != 0) {
          chmax(ans, A);
        }

        long[] ps;
        long b = B;
        for (long p = 2; p^^2 <= b; ++p) {
          if (b % p == 0) {
            do {
              b /= p;
            } while (b % p == 0);
            ps ~= p;
          }
        }
        if (b > 1) {
          ps ~= b;
        }

        foreach (p; ps) {
          long a = A;
          for (; a % B == 0; a /= p) {}
          chmax(ans, a);
        }

        writeln(ans);
      }
    }
  } catch (EOFException e) {
  }
}

// Cheese-Cracker: cheese-cracker.github.io

ll[] primes;

void play(){
    ll p, q;
    p = rd; q = rd;
    ll P = p, Q = q;

    // Base
    if(p % q != 0){
        writeln(p);
        return;
    }

    // Prime Factorize
    ll[] pfact;
    int[] cntp;
    foreach(prime; primes){
        int isin = 0;
        while(q % prime == 0 && q > 1){
            q /= prime;
            ++isin;
        }
        if(isin){
            pfact ~= prime;
            cntp ~= isin;
        }
    }
    if(q != 1){ pfact ~= q; cntp ~= 1; }
    show(pfact);

    ll mindiv = -1;
    foreach(i; 0.. pfact.length){
        ll prime = pfact[i];
        ll k = 1;
        while(p % prime == 0 && p > 1){
            p /= prime;
            k *= prime;
        }
        foreach(j; 1..cntp[i]){
            k /= prime;
        }
        show(k);
        if(mindiv == -1){
            mindiv = k;
        }else{
            mindiv = min(mindiv, k);
        }
        show(mindiv);
    }
    writeln(P/mindiv);
}

int main(){
    // Sieve
    const int SZ = 100000;
    ll[SZ+1] notprime;
    foreach(p; 2..1000){
        if(!notprime[p]){
            for(int div = p*p; div <= SZ; div += p){
                notprime[div] = 1;
            }
        }
    }
    foreach(i; 2..SZ){
        if(!notprime[i]){
            primes ~= i.to!long;
        }
    }
    long t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

int [] divisors (int n)
{
	int [] res;
	for (int d = 2; d * d <= n; d++)
	{
		if (n % d == 0)
		{
			res ~= d;
			while (n % d == 0)
			{
				n /= d;
			}
		}
	}
	if (n > 1)
	{
		res ~= n;
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		long p;
		int q;
		readf !(" %s %s") (p, q);
		auto d = divisors (q);

		long res = 1;

		void recur (long cur, int i)
		{
			if (cur % q != 0)
			{
				res = max (res, cur);
			}
			if (i >= d.length)
			{
				return;
			}
			recur (cur, i + 1);
			while (cur % d[i] == 0)
			{
				cur /= d[i];
				recur (cur, i + 1);
			}
		}

		recur (p, 0);
		writeln (res);
	}
}

// Cheese-Cracker: cheese-cracker.github.io

ll[] primes;

void play(){
    ll p, q;
    p = rd; q = rd;
    ll P = p, Q = q;

    // Base
    if(p % q != 0){
        writeln(p);
        return;
    }

    // Prime Factorize
    ll[] pfact;
    foreach(prime; primes){
        bool isin = 0;
        while(q % prime == 0 && q > 1){
            q /= prime;
            isin = 1;
        }
        if(isin){
            pfact ~= prime;
        }
    }
    if(q != 1){ pfact ~= q; }
    show(pfact);

    ll mindiv = -1;
    foreach(ll prime; pfact){
        ll k = 1;
        while(p % prime == 0 && p > 1){
            p /= prime;
            k *= prime;
        }
        show(k);
        if(mindiv == -1){
            mindiv = k;
        }else{
            mindiv = min(mindiv, k);
        }
        show(mindiv);
    }
    writeln(P/mindiv);
}

int main(){
    // Sieve
    const int SZ = 100000;
    ll[SZ+1] notprime;
    foreach(p; 2..1000){
        if(!notprime[p]){
            for(int div = p*p; div <= SZ; div += p){
                notprime[div] = 1;
            }
        }
    }
    foreach(i; 2..SZ){
        if(!notprime[i]){
            primes ~= i.to!long;
        }
    }
    long t = 1;
    t = rd;        // Toggle!
    while(t--) play();  // Let's play!
    stdout.flush;
    return 0;
}

/**********It's A Me Mario!**********/
import std.stdio, std.conv, std.functional, std.string, std.algorithm;
import std.container, std.range, std.typecons, std.numeric, std.math, std.random;
static string[] inp;
T rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}
T[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }
void show(A...)(A a) { debug{ foreach(t; a){ write(t, "| "); } writeln; } }
alias ll = long;
alias rbt = redBlackTree;
alias tup = Tuple!(long, "x",  long, "y");
T max(T = long)(T a, T b){ return (a > b) ? a : b; }
T min(T = long)(T a, T b){ return (a < b) ? a : b; }


import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.utf;

auto savings (R) (R r)
{
	int balance = 0;
	int res = 0;
	foreach (const ref cur; r)
	{
		balance += cur ? +1 : -1;
		balance = max (balance, 0);
		res = max (res, balance);
	}
	return res;
}

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		int n, k;
		readf !(" %s %s") (n, k);
		readln;
		auto s = readln.strip.map !(q{a == '1'}).array;
		int total = s.sum;
		int res = total;
		foreach (start; 0..k)
		{
			res = min (res, total -
			    savings (s.drop (start).stride (k)));
		}
		writeln (res);
	}
}

import std.stdio;
import std.uni;
import std.conv;
import std.container;
import std.functional;
import std.algorithm;
import std.array;
import std.typecons;
import std.range;
import std.numeric;
import std.traits;

void main(string[] args)
{
  auto t = next!int;
 tcl: foreach(tc; 0 .. t)
    {
      auto n = next!int;
      auto k = next!int;
      auto s = next!char(n);
      auto totalModuloCount = new int[](k);
      auto rightModuloCount = new int[](k);
      auto no1s = s.count!(c => c == '1');
      foreach(i, c; s) if (c == '1') totalModuloCount[cast(int)i % k]++;
      rightModuloCount[] = totalModuloCount[];
      auto bestEnding = new int[](n);
      auto bestEndingPerClass = new int[](k);
      debug writeln(totalModuloCount);
      bestEndingPerClass[] = 1_000_000_0;
      foreach(i; 0 .. n)
	{
	  auto moduloClass = cast(int) i % k;
	  if (s[i] == '1')
	    {
	      rightModuloCount[moduloClass]--;
	    }
	  if (i - k >= 0)
	    {
	      debug
		{
		  if (i == 3)
		    {
		      writeln("current cost: ", - int(s[i] == '1')  + int(s[i] != '1'));
		      writeln(bestEnding);
		      writeln("comparing ", totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1'),
			      " with ", bestEnding[i - k] - int(s[i] == '1') + int(s[i] != '1'));
		    }
		}
	      bestEnding[i] = min(totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1'),
				  bestEnding[i - k] - int(s[i] == '1') + int(s[i] != '1'));
	    }
	  else
	    {
	      bestEnding[i] = totalModuloCount[moduloClass] - int(s[i] == '1') + int(s[i] != '1');
	    }
	  bestEndingPerClass[moduloClass] = min(bestEndingPerClass[moduloClass],
						bestEnding[i]);
	}
      debug writeln(bestEnding);
      debug writeln(bestEndingPerClass);
      int bestTotal = cast(int)no1s;
      foreach(cl; 0 .. k)
	{
	  bestTotal = min(bestTotal, bestEndingPerClass[cl] + no1s - totalModuloCount[cl]);
	}
      bestTotal.writeln;
    }
}

static this()
{
  popChar;
}

struct Any(T)
{
  static auto read()
  {
    static if (is(T == char))
      {
	auto res = frontChar;
	popChar;
	return res;
      }
  }
}

struct Unsigned(T)
{
  auto read()
  {
    auto res = T(0);
    while(!frontChar.isDigit) popChar;
    do
      {
	res = res * T(10) + T(frontChar - '0');
	popChar;
      }
    while(frontChar.isDigit);
    return res;
  }
}

struct Matrix(T, alias rows, alias cols)
{
  T[][] _cell;
  alias _cell this;
  // Ring constructor
  this(int n)
  {
    final switch(n)
      {
      case 0:
	_cell = new T[][](rows, cols);
	break;
      case 1:
	debug assert(rows == cols);
	_cell = new T[][](rows, cols);
	foreach(i; 0 .. rows)
	  _cell[i][i] = T(1);
	break;
      }
  }
  // Copy constructor
  this(Matrix!(T, rows, cols) other)
  {
    _cell = new T[][](rows, cols);
    foreach(i; 0 .. rows)
      _cell[i][] = other[i][];
  }
  auto opBinary(string op)(Matrix!(T, rows, cols) other)
       if (op == "+" || op == "-")
	 {
	   auto res = Matrix!(T, rows, cols)(0);
	   foreach(i; 0 .. rows)
	     foreach(j; 0 .. cols)
	       res[i][j] = mixin(q{this[i][j]}, op, q{other[i][j]});
	   return res;
	 }
  auto opBinary(string op, alias otherRows, alias otherCols)(Matrix!(T, otherRows, otherCols) other)
       if (op == "*")
	 {
	   debug assert(cols == otherRows);
	   auto res = Matrix!(T, rows, otherCols)(0);
	   foreach(i; 0 .. rows)
	     foreach(k; 0 .. cols)
	       foreach(j; 0 .. otherCols)
		 res[i][j] += this[i][k] * other[k][j];
	   return res;
	 }
  ref auto opOpAssign(string op)(Matrix!(T, rows, cols) other)
  {
    static if (op == "*")
      {
	debug assert(rows == cols);
	alias n = rows;
	auto res = Matrix!(T, n, n)(0);
	T factor;
	foreach(i; 0 .. n)
	  foreach(k; 0 .. n)
	    foreach(j; 0 .. n)
	      res[i][j] += this[i][k] * other[k][j];
	foreach(i; 0 .. n)
	  this[i][] = res[i][];
      }
    else
      {
	foreach(i; 0 .. rows)
	  foreach(j; 0 .. cols)
	    mixin(q{this[i][j] }, text(op, q{=}), q{ other[i][j];});
      }
    return this;
  }
  mixin powMethod;
}

struct Mod(T, alias mod)
{
  alias This = Mod!(T, mod);
  T _rep;
  this(T t)
  {
    _rep = t % mod;
    if (_rep < 0) _rep += mod;
  }
  static auto plain(T t)
  {
    auto res = Mod!(T, mod)();
    res._rep = t;
    return res;
  }
  static auto fromPositive(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod);
  }
  static auto fromNegative(T t)
  {
    pragma(inline, true);
    return Mod!(T, mod).plain(t % mod + mod);
  }
  string toString()
  {
    return to!string(_rep);
  }
  debug invariant
  {
    assert(_rep >= 0 && _rep < mod);
  }
  auto opBinary(string op)(This b)
  {
    static if (op == "+")
      {
	T resrep = _rep + b._rep;
	if (resrep >= mod) resrep -= mod;
	return This.plain(resrep);
      }
    else static if (op == "-")
      {
	T resrep = _rep - b._rep;
	if (resrep < 0) resrep += mod;
	return This.plain(resrep);
      }
    else static if (op == "*")
      {
	return This.fromPositive(_rep * b._rep);
      }
  }
  auto opOpAssign(string op)(This b)
  {
    mixin(q{_rep }, text(op, "="), q{b._rep;});
    static if (op == "+")
      {
	if (_rep >= mod) _rep -= mod;
      }
    else static if (op == "-")
      {
	if (_rep < 0) _rep += mod;
      }
    else static if (op == "*")
      {
	_rep %= mod;
      }
    return this;
  }

  auto opBinary(string op)(long exp)
       if (op == "^^")
	 {
	   return pow(exp);
	 }
  mixin powMethod;
}

mixin template powMethod()
{
  auto pow(this ThisType)(long exp)
    {
      auto res = ThisType(1);
      auto pow = ThisType(this);
      while(exp)
	{
	  if (exp & 1) res *= pow;
	  pow *= pow;
	  exp >>= 1;
	}
      return res;
    }
}
// INPUT
char frontChar;
void popChar()
{
  import core.stdc.stdio;
  frontChar = cast(char) getchar;
  if (feof(stdin)) frontChar = ' ';
}
auto makeArray(T, S...)(S s)
{
  enum brackets = () {
    string res;
    foreach(i; 0 .. s.length)
      res ~= "[]";
    return res;
  } ();
  mixin(q{alias Type = T}, brackets, q{;});
  return new Type(s);
}
template isNumberLike(T)
{
  enum isNumberLike = is(typeof((){T test; test = test + test * test; test *= test;}()));
}
void popWhite()
{
  import std.ascii;
  while (frontChar.isWhite) popChar;
}
void print(T...)(T t)
{
  static foreach(ti; t)
    {
      static if (is(typeof(ti) == string))
	{
	  write(ti, " ");
	}
      else static if (isArray!(typeof(ti)))
	{
	  foreach(e; ti) print(e);
	}
      else static if (isTuple!(typeof(ti)))
	{
	  static foreach(i; ti.length) writesp(ti[i]);
	}
      else
	{
	  write(ti, " ");
	}
    }
}
void println(T...)(T t)
{
  static if (t.length == 0)
    writeln;
  static foreach(ti; t)
    {
      print(ti);
      writeln;
    }
}
auto next(alias T, S...)(S s)
{
  pragma(inline, true);
  static if (s.length > 0)
    {
      auto res = makeArray!(typeof(next!T()))(s);
      S t;
      enum loops = () {
	string res;
	foreach(i; 0 .. s.length)
	  {
	    auto ti = text(q{t[}, i, q{]});
	    res ~= text(q{for(}, ti, q{ = 0;}, ti , q{ < s[}, i, q{];}, ti, q{++)});
	  }
	return res;
      } ();
      enum indexing = () {
	string res = "res";
	foreach(i; 0 .. s.length)
	  res ~= text(q{[t[}, i, q{]]});
	return res;
      } ();
      mixin(loops, indexing, q{ = next!T;});
      return res;
    }
  else
    {
      static if (isNumberLike!T)
	{
	  import std.ascii: isDigit;
	  T res;
	  while(frontChar.isWhite) popChar;
	  T multiplier = T(1);
	  if (frontChar == '-')
	    {
	      multiplier = T(-1);
	      popChar;
	    }
	  else if (frontChar == '+')
	    {
	      popChar;
	    }
	  debug assert(frontChar.isDigit);
	  do
	    {
	      res = res * T(10) + T(frontChar - '0');
	      popChar;
	    }
	  while(frontChar.isDigit);
	  return multiplier * res;
	}
      else static if (is(T == string))
	{
	  import std.ascii: isWhite;
	  string res;
	  while(frontChar.isWhite)
	    popChar;
	  while(!frontChar.isWhite)
	    {
	      res ~= frontChar;
	      popChar;
	    }
	  return res;
	}
      else static if (is(T == char))
	{
	  while(frontChar.isWhite) popChar;
	  auto res = frontChar;
	  popChar;
	  return res;
	}
      else
	{
	  return T.read;
	}
    }
}


module _template;
import std.stdio;
import std.string;
import std.algorithm;
import std.container;
import std.range;
import std.math;
import std.numeric;
import std.conv;
import std.typecons;
import std.format;

struct IO {
        string[] tk;
        string readString() {
                while (tk.empty)
                        tk = readln.split;
                auto tkt = tk.front;
                tk.popFront;
                return tkt;
        }
        int readInt() {
                return readString.to!int;
        }
        double readDouble() {
                return readString.to!double;
        }
}

int solve(int a, int b) {
        if (a == 0 || b == 0) return 0;
        else return max(a, b) / min(a, b) + solve(max(a, b) % min(a, b), min(a, b));
}
void main() {
        IO cin;
        int t = 1;
        t = cin.readInt;
        while (t--) {
                int a = cin.readInt;
                int b = cin.readInt;
                int count = 0;
                writeln(solve(a, b));
        }
}

import std.stdio;

int steps (int a, int b)
{
	if (b == 0)
	{
		return 0;
	}
	return a / b + steps (b, a % b);
}

int main ()
{
        int tests;
        readf (" %s", &tests);
	foreach (test; 0..tests)
	{
		int a, b;
		readf (" %s %s", &a, &b);
		writefln ("%s", steps (a, b));
	}
	return 0;
}


import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    int n;
    readf!" %d "(n);
    auto a = readln.splitter.map!(to!int).array;
    auto mx = a.maxElement;
    if (mx != a[0] && mx != a[$ - 1]) {
      writeln(-1);
      continue;
    }
    if (mx == a[0])
      a = a[1 .. $];
    else
      a = a[0 .. $ - 1];
    writefln("%(%s %)", [mx] ~ a.reverse);
  }
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.splitter.map !(to !(int)).array;
		if (a.front == n || a.back == n)
		{
			a.retro.writefln !("%(%s %)");
		}
		else
		{
			writeln (-1);
		}
	}
}


import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math :pow;

alias Tree = RBT!int;

void main() {
    GC.disable();

    int t;
    readf(" %s", t);

    int[][] factors = new int[] [1_000_009];
    bool[] primes = new bool [1_000_009];
    primes[] = true;
    foreach(i; 2 .. 1_000_000) {
      if (primes[i]) {
        factors[i] ~= i;

        for(uint j = 2*i; j <= 1_000_000; j += i) {
          primes[j] = false;
          factors[j] ~= i;
        }
      }
    }

    foreach(q; 0 .. t) {

      uint n;

      readf(" %s", n);

      auto d = new int [n];
      int[int] allprimes;

      foreach(i; 0 .. n) {
        readf(" %s", d[i]);

        foreach(p; factors[ d[i] ]) {
          int pow = 0;
          int t_ = d[i];
          while ( t_ % p == 0) { pow++; t_ /= p; }

          if (p in allprimes) {
            allprimes[p] = max( allprimes[p], pow );
          } else {
            allprimes[p] = pow;
          }
        }
      }

      long num_divisors = 1;
      long x =1 ;
      long sp = -1;
      foreach(k,v; allprimes) {
        // writeln(k, " ", v);
        sp = v;
        num_divisors *= (v+1);
        if (num_divisors > n+2) break;
        x *= pow(k, v);
      }

      long ans = -1;
      if (num_divisors > n+2) { writeln(-1); }
      else if (d.canFind(x)) {
        foreach(k, v; allprimes) {
          auto new_num_divisors = num_divisors / (v+1) * (v+2);
          if (new_num_divisors == n+2) {
            auto newx = x * k;
            if (ans == -1) ans = newx; else ans = min(ans, newx);
          }
        }

        if (ans != -1) writeln(ans); else writeln(-1);
      }
      else if (n==1) {
        if (primes[d[0]]) writeln(d[0]*d[0]); else writeln(-1);
      } else if (allprimes.length == 1) {
        if (num_divisors == n + 1) {
          writeln(x*sp);
        } else {
          writeln(-1);
        }

      } else if (num_divisors != n+2) writeln(-1);
      else {
        writeln(x);
      }

    }
}

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void solve() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    A.sort();

    long ans = -1;

    for (int i = 0; i <= N - i - 1; ++i) {
        if (ans == -1) {
            ans = A[i] * A[N-i-1];
        } else if (ans != A[i] * A[N-i-1]) {
            writeln(-1);
            return;
        }
    }

    long[] F;
    for (long i = 2; i * i <= ans; ++i) {
        if (ans % i == 0) {
            F ~= i;
            if (i * i != ans) {
                F ~= ans / i;
            }
        }
    }
    F.sort();

    writeln(F == A ? ans : -1);
}

void main() {
    auto N = readln.chomp.to!int;
    while (N--) solve;
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int t = read.to!int;

	foreach(q; 0 .. t){

		int n = read.to!int;
		long[] as;
		foreach(i; 0 .. n) as ~= read.to!long;

		as.sort!();

		long x = as[0] * as[$ - 1];
		int flag = 1;

		int k = 0;
		for(long d = 2; d * d <= x; d ++){
			if(x % d == 0){
				if(as[k] == d && as[$ - 1 - k] == x / d){
					k += 1;
					continue;
				}
				else flag = -1;
			}
		}
		if(k <= n - 1 - k) flag = -1;

		if(flag < 0) "-1".writeln;
		else x.writeln;

	}
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int t = read.to!int;

	foreach(q; 0 .. t){

		int n = read.to!int;
		int[] as;
		foreach(i; 0 .. n) as ~= read.to!int;

		as.sort!();

		int x = as[0] * as[$ - 1];
		int flag = 1;

		int k = 0;
		for(int d = 2; d * d <= x; d ++){
			if(x % d == 0){
				if(as[k] == d && as[$ - 1 - k] == x / d){
					k += 1;
					continue;
				}
				else flag = -1;
			}
			else{
				if(as[k] != d) continue;
				else flag = -1;
			}
		}
		if(k <= n - 1 - k) flag = -1;

		if(flag < 0) "-1".writeln;
		else x.writeln;

	}
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math :pow;

alias Tree = RBT!int;

void main() {
    GC.disable();

    int t;
    readf(" %s", t);

    int[][] factors = new int[] [1_000_009];
    bool[] primes = new bool [1_000_009];
    primes[] = true;
    foreach(i; 2 .. 1_000_000) {
      if (primes[i]) {
        factors[i] ~= i;

        for(uint j = 2*i; j <= 1_000_000; j += i) {
          primes[j] = false;
          factors[j] ~= i;
        }
      }
    }

    foreach(q; 0 .. t) {

      uint n;

      readf(" %s", n);

      auto d = new int [n];
      int[int] allprimes;

      foreach(i; 0 .. n) {
        readf(" %s", d[i]);

        foreach(p; factors[ d[i] ]) {
          int pow = 0;
          int t_ = d[i];
          while ( t_ % p == 0) { pow++; t_ /= p; }

          if (p in allprimes) {
            allprimes[p] = max( allprimes[p], pow );
          } else {
            allprimes[p] = pow;
          }
        }
      }

      long num_divisors = 1;
      long x =1 ;
      long sp = -1;
      foreach(k,v; allprimes) {
        // writeln(k, " ", v);
        sp = v;
        num_divisors *= (v+1);
        if (num_divisors > n+2) break;
        x *= pow(k, v);
      }

      if (n==1) {
        if (primes[d[0]]) writeln(d[0]*d[0]); else writeln(-1);
      } else if (allprimes.length == 1) {
        if (num_divisors == n + 1) {
          writeln(x*sp);
        } else {
          writeln(-1);
        }

      } else if (num_divisors != n+2) writeln(-1);
      else {
        writeln(x);
      }

    }
}

import std.stdio : writef, readf, readln, writeln, writefln;
import std.array : array, split;
import std.algorithm;
import std.conv : to;
import std.range : iota, tee;
import std.algorithm.comparison;
import std.container.rbtree : RBT = RedBlackTree;
import std.string : strip;
import core.memory : GC;
import std.typecons : tuple;
import std.math :pow;

alias Tree = RBT!int;

void main() {
    GC.disable();

    int t;
    readf(" %s", t);

    int[][] factors = new int[] [1_000_009];
    bool[] primes = new bool [1_000_009];
    primes[] = true;
    foreach(i; 2 .. 1_000_000) {
      if (primes[i]) {
        factors[i] ~= i;

        for(uint j = 2*i; j <= 1_000_000; j += i) {
          primes[j] = false;
          factors[j] ~= i;
        }
      }
    }

    foreach(q; 0 .. t) {

      uint n;

      readf(" %s", n);

      auto d = new int [n];
      int[int] allprimes;

      foreach(i; 0 .. n) {
        readf(" %s", d[i]);

        foreach(p; factors[ d[i] ]) {
          int pow = 0;
          int t_ = d[i];
          while ( t_ % p == 0) { pow++; t_ /= p; }

          if (p in allprimes) {
            allprimes[p] = max( allprimes[p], pow );
          } else {
            allprimes[p] = pow;
          }
        }
      }

      long num_divisors = 1;
      long x =1 ;
      foreach(k,v; allprimes) {
        // writeln(k, " ", v);
        num_divisors *= (v+1);
        if (num_divisors > n+2) break;
        x *= pow(k, v);
      }

      if (n==1) {
        if (primes[d[0]]) writeln(d[0]*d[0]);
        else writeln(-1);
      } else
      if (num_divisors != n+2) writeln(-1);
      else {
        writeln(x);
      }

    }
}