This page is still under construction.

Parts of this page are still being built. What you see may change.

Anagrams

Interview

Time limit1sMemory limit128 MB

Summary
Given two lowercase words, decide whether one can be rearranged into the other, and print the result with the words.
Level

Easy2 of 10

Topics
String, Hash map, Sorting
Solved
No attempts yet

Problem

Two words AA and BB are given. If you can rearrange the order of the letters in AA to form BB, then AA and BB are called anagrams of each other.

Write a program that determines whether two given words are anagrams.

Input

The first line contains the number of test cases TT (T<100T < 100).

Each of the following test cases consists of a single line containing two words separated by a space. Each word has length at most 100100 and consists only of lowercase English letters.

Output

For each test case, if the two words are anagrams, print

A & B are anagrams.

Otherwise, print

A & B are NOT anagrams.

on its own line, where A and B are the two words given in the input.

Examples1

  1. Example 1

    Input
    3
    blather reblath
    maryland landam
    bizarre brazier
    
    Expected output
    blather & reblath are anagrams.
    maryland & landam are NOT anagrams.
    bizarre & brazier are anagrams.