**Compilation/Execution Result:**

Given An array of Alphabets and their frequency. Your task is to print all the given alphabets Huffman Encoding.

**Note: **If two elements have same frequency, then the element which if at first will be taken on left of Binary Tree and other one to right.

**Input:**

First line consists of test cases T. First line of every test case consists of string of alphabets and second line consists of its frequencies.

**Output:**

Print the HuffmanCodes in single line, with n spaces of each alphabet's HuffmanCodes respectively. In PreOrder form of Binary Tree.

**Constraints:**

1<=T<=100

1<=|String length|<=26

**Example:
Input:**

1

abcdef

5 9 12 13 16 45

0 100 101 1100 1101 111

**Explanation:**

For the above test case.

HuffmanCodes will be

f: 0

c: 100

d: 101

a: 1100

b: 1101

e: 111

Print in the PreOrder of Binary Tree.

Author: saksham seth

Pulkit Gupta 2 | 114 |

nancygarg258_pec | 90 |

Little Noah | 84 |

rs119574 | 82 |

Relentless | 81 |

Ibrahim Nash | 580 |

KartikAgarwal | 541 |

rs119574 | 371 |

surbhi_7 | 356 |

Little Noah | 333 |

akhayrutdinov | 4261 |

sanjay05 | 3633 |

Ibrahim Nash | 3140 |

Quandray | 3028 |

Michael Riegger | 2359 |