class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.y: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.txt = txt

c = A("c")
l = B("l")
m = C("m")
a = B("a")
n = A("n")
g = C("g")

c.s = n
c.y = g
l.y = g
m.r = g
m.y = c
a.y = g
n.s = c
n.y = m
g.r = m
g.y = n
assert m.y.y.r.y.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.y: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.txt = txt

c = A("c")
l = B("l")
m = C("m")
a = B("a")
n = A("n")
g = C("g")

c.s = n
c.y = g
l.y = g
m.r = g
m.y = c
a.y = g
n.s = c
n.y = m
g.r = m
g.y = n
assert m.y.y.r.y.y.r.txt == "m"