#P40. [KBC002Ex] String 2

[KBC002Ex] String 2

Source

This problem is adapted from Long Long OJ. All rights reserved.

Problem Description

There is a transfrom ff defined as follows: f(A)T,f(\tt{A})\to\tt{T},f(C)G,f(\tt{C})\to\tt{G},f(G)C,f(\tt{G})\to\tt{C},f(T)A.f(\tt{T})\to\tt{A}.

Given a string SS consisting of characters ACGT\tt{ACGT}, find the lexicographically smallest string that can be obtained after applying the following operations:

  • Choose a non-empty substring of SS (let's call it TT).
  • Perfrom the transfrom ff once for each character in the substring TT.
  • Reverse the substring TT.

Input Format

Each test consists of multiple testcases.

For each testcase, you should input a string SS consisting of characters ACGT\tt{ACGT}.

Output Format

For each testcase, you should output a string representing the lexicographically smallest string that can be obtained after applying the operations above.

Samples

ACGTACGT
ACACACAC
AACGACGT
ACACACAG

Sample Explanation

In the first testcase, It's best to choose the second to fourth characters (ACGTACGT\tt{A\color{red}{CGT}\color{black}ACGT}) of SS.

In the second testcase, It's best to choose the last character (ACACACAC\tt{ACACACA\color{red}{C}}) of SS.

Data Range

There are 55 tests, each of which is worth 2020 points:

  1. SS appeared in the sample input.
  2. S=1.|S|=1.
  3. S8.|S| \le 8.
  4. All the characters in the string SS are the same.
  5. No additional constraints.

For 100%100\% of the testcases, 1S105.1 \le |S| \le 10^5.

It is guaranteed that the sum of S|S| over all the testcases in one test does not exceed 10610^6.