import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;

int[3][2][] mkKey(string[] e) {
	int[3][2][] key;
	int[3][string] bar = ["+x": [1,0,0], "-x": [-1,0,0], "+y":[0,1,0], "-y":[0,-1,0], "+z":[0,0,1], "-z":[0,0,-1]];
	int[3][int] label;
	int[3] pos = [0,0,0];
	foreach(ei; e) {
		if(ei.isNumeric()) {
			int n = to!int(ei);
			if(n in label) {
				pos = label[n];
			} else {
				label[n] = pos;
			}
		} else {
			int[3] end = pos[]+bar[ei][];
			key ~= [pos,end];
			if(key[$-1][0] > key[$-1][1])
				swap(key[$-1][0], key[$-1][1]);
			pos = end;
		}
	}
	return moveKey(key);
}
int[3][2][] moveKey(int[3][2][] key) {
	int[3] origin = key[0][0];
	foreach(bar; key){
		foreach(p; bar) {
			if(p < origin)
				origin = p;
		}
	}
	foreach(i; 0..key.length) {
		key[i][0][] -= origin[];
		key[i][1][] -= origin[];
	}
	key.sort();
	return key;
}
int[] rot(int[] v, int[2][2] m) {
	return [m[0][0]*v[0]+m[0][1]*v[1], m[1][0]*v[0]+m[1][1]*v[1]];
}

int[3][2][] rotKey(int[3][2][] key, int[2][2] m0, int[2][2] m1, int[2][2] m2) {
	auto ret = key.dup;
	foreach(i; 0..key.length) {
		foreach(j; 0..2){
			ret[i][j][0..2] = rot(ret[i][j][0..2], m0);
			ret[i][j][1..3] = rot(ret[i][j][1..3], m1);
			ret[i][j][0..2] = rot(ret[i][j][0..2], m2);
		}
		if(ret[i][0] > ret[i][1])
			swap(ret[i][0], ret[i][1]);
	}
	return moveKey(ret);
}

void main() {
	int[2][2][] rot = [[[1, 0],[0,1]], [[0,1],[-1, 0]], [[0, -1],[1,0]], [[-1, 0],[0,-1]]];

	auto l = array(readln().strip().split());
	int n = to!int(l[0]);
	while(n) {
		auto s = l[1..$];
		while(s.length < n) {
			s ~= array(readln().strip().split());
		}
		auto key1 = mkKey(s);

		l = array(readln().strip().split());
		n = to!int(l[0]);
		s = l[1..$];
		while(s.length < n) {
			s ~= array(readln().strip().split());
		}
		auto key2 = mkKey(s);

		bool same;
		foreach(i; 0..4) {
			foreach(j; 0..4) {
				foreach(k; 0..4) {
					same |= (key1 == rotKey(key2, rot[i], rot[j], rot[k]));
				}
			}
		}
		writeln(same ? "SAME":"DIFFERENT");
		l = array(readln().strip().split());
		n = to!int(l[0]);
	}
}