Codeforces Round #760 (Div. 3) B. Missing Bigram

题目链接:Problem - B - Codeforces

Polycarp has come up with a new game to play with you. He calls it "A missing bigram".

A bigram of a word is a sequence of two adjacent letters in it.

For example, word "abbaaba" contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".

The game goes as follows. First, Polycarp comes up with a word, consisting only of lowercase letters 'a' and 'b'. Then, he writes down all its bigrams on a whiteboard in the same order as they appear in the word. After that, he wipes one of them off the whiteboard.

Finally, Polycarp invites you to guess what the word that he has come up with was.

Your goal is to find any word such that it's possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.

The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

Input

The first line contains a single integer tt (1≤t≤2000) — the number of testcases.

The first line of each testcase contains a single integer nn (3≤n≤100) — the length of the word Polycarp has come up with.

The second line of each testcase contains n−2 bigrams of that word, separated by a single space. Each bigram consists of two letters, each of them is either 'a' or 'b'.

Additional constraint on the input: there exists at least one string such that it is possible to write down all its bigrams, except one, so that the resulting sequence is the same as the sequence in the input. In other words, the answer exists.

Output

For each testcase print a word, consisting of n letters, each of them should be either 'a' or 'b'. It should be possible to write down all its bigrams and remove one of them, so that the resulting sequence of bigrams is the same as the one Polycarp ended up with.

The tests are generated in such a way that the answer exists. If there are multiple answers, you can print any of them.

Example

input

4
7
ab bb ba aa ba
7
ab ba aa ab ba
3
aa
5
bb ab bb

output

abbaaba
abaabaa
baa
bbabb

Note

The first two testcases from the example are produced from the word "abbaaba". As listed in the statement, it contains bigrams "ab", "bb", "ba", "aa", "ab" and "ba".

In the first testcase, the 5-th bigram is removed.

In the second testcase, the 2-nd bigram is removed. However, that sequence could also have been produced from the word "abaabaa". It contains bigrams "ab", "ba", "aa", "ab", "ba" and "aa". The missing bigram is the 6-th one.

In the third testcase, all of "baa", "aab" and "aaa" are valid answers.

题意:将一个字符串拆成了两两相连的多个子串,然后删除一个,让你构造原本的字符串

思路:如果上个子串的第二个字母和下个子串的第一个字母相同就是连续的,如果不相同就说明中间被删除了一个,然后这个子串就是这两个字母,然后全部都相同就在最后补一个‘a’;

#include<bits/stdc++.h>
using namespace std;

string s[105];

int main(){
	int t;
	int n;
	cin >> t;
	while(t--){
		cin >> n;
		for(int i = 0; i < n - 2; i++){
			cin >> s[i];
		}
		string ss = "";
		ss += s[0];
		bool flag = 0;
		for(int i = 1; i < n - 2; i++){
			if(s[i][0] != s[i - 1][1]){
				ss += s[i][0];
				flag = 1;
			}
			ss += s[i][1];
		}
		if(flag == 0){
			ss += "a";
		}
		cout << ss << endl;
	}
	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值