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

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

f = A("f")
m = B("m")
c = B("c")
i = A("i")
g = A("g")
h = B("h")
a = A("a")
k = A("k")

f.y = i
f.z = a
m.q = h
c.q = m
i.y = f
i.z = k
g.y = k
g.z = i
h.q = c
a.y = k
a.z = k
k.y = a
k.z = i
assert a.z.z.y.y.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: A = None
        self.txt = txt

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

f = A("f")
m = B("m")
c = B("c")
i = A("i")
g = A("g")
h = B("h")
a = A("a")
k = A("k")

f.y = i
f.z = a
m.q = h
c.q = m
i.y = f
i.z = k
g.y = k
g.z = i
h.q = c
a.y = k
a.z = k
k.y = a
k.z = i
assert a.z.z.y.y.z.y.z.txt == "k"