#ifdef _DEBUG
#pragma warning(disable : 4996)
#endif
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define CLOSE() ios::sync_with_stdio(false)
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define PF(a) printf("%d\n", a)
#define SF(a) scanf("%d", &a)
#define SFF(a, b) scanf("%d%d", &a, &b)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define LL long long
#define MAXN 100005
#define MAXM 1000010
#define mod 1000007
#define INF 1000000000
using namespace std;
//------------------------------------------------------------------------------------------//
//习题5 - 11 更新字典(Updating a Dictionary, UVa12504)
//注意值为空的情况
//substr 第二个参数为子串的长度
map<string, string> dic, dic2;
set<string> add, decrease, change;
void solve() {
for (auto i : dic) {
string k = i.first, v = i.second;
if (!dic2.count(k)) decrease.insert(k);
else {
if (v != dic2[k]) change.insert(k);
}
}
for (auto i : dic2) {
string k = i.first, v = i.second;
if (!dic.count(k)) add.insert(k);
}
}
int main() {
#ifdef _DEBUG
IN(); OUT();
#endif
int T; SF(T);
while (T--) {
dic.clear();
add.clear();
decrease.clear();
change.clear();
dic2.clear();
string s;
cin >> s;
bool ok = false;
int p0 = 1, p1 = s.find(':'), p2 = s.find(','), p3 = s.find('}');
if (p2 == -1) p2 = p3, ok = true;
if (p1 == -1) goto here;
while (1) {
string k = s.substr(p0, p1-p0), v = s.substr(p1 + 1, p2-p1-1);
//cout << k << v << endl;
dic[k] = v;
if (ok) break;
p0 = p2 + 1;
p1 = s.find(':', p0);
p2 = s.find(',', p0);
if (p2 == -1) p2 = p3, ok = true;
}
here:
cin >> s;
ok = false;
p0 = 1, p1 = s.find(':'), p2 = s.find(','), p3 = s.find('}');
if (p1 == -1) goto there;
if (p2 == -1) p2 = p3, ok = true;
while (1) {
string k = s.substr(p0, p1 - p0), v = s.substr(p1 + 1, p2 - p1 - 1);
//cout << k << v << endl;
dic2[k] = v;
if (ok) break;
p0 = p2 + 1;
p1 = s.find(':', p0);
p2 = s.find(',', p0);
if (p2 == -1) p2 = p3, ok = true;
}
there :
solve();
bool have = false;
if (add.size()) {
have = true;
cout << '+';
bool first = true;
for (auto i : add) {
if (first) first = false;
else cout << ',';
cout << i;
}
cout << endl;
}
if (decrease.size()) {
have = true;
cout << '-';
bool first = true;
for (auto i : decrease) {
if (first) first = false;
else cout << ',';
cout << i;
}
cout << endl;
}
if (change.size()) {
have = true;
cout << '*';
bool first = true;
for (auto i : change) {
if (first) first = false;
else cout << ',';
cout << i;
}
cout << endl;
}
if (!have) cout << "No changes\n";
cout << endl;
}
return 0;
}