import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool solve (string s, string [] t)
{
	if (t.canFind (s))
	{
		return true;
	}
	foreach (a; t)
	{
		foreach (b; t)
		{
			if ("" ~ a[1] ~ b[0] == s)
			{
				return true;
			}
		}
	}
	return false;
}

void main ()
{
	string s;
	while ((s = readln.strip) != "")
	{
		int n = readln.strip.to !(int);
		string [] t;
		foreach (i; 0..n)
		{
			t ~= readln.strip;
		}
		writeln (solve (s, t) ? "YES" : "NO");
	}
}
