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

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

f = A("f")
i = B("i")
l = B("l")
d = A("d")
m = B("m")
b = B("b")
g = A("g")
j = B("j")
n = A("n")

f.y = d
i.q = m
i.z = n
l.q = j
l.z = g
d.y = n
m.q = i
m.z = f
b.q = l
b.z = d
g.y = f
j.q = m
j.z = f
n.y = d
assert d.y.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

f = A("f")
i = B("i")
l = B("l")
d = A("d")
m = B("m")
b = B("b")
g = A("g")
j = B("j")
n = A("n")

f.y = d
i.q = m
i.z = n
l.q = j
l.z = g
d.y = n
m.q = i
m.z = f
b.q = l
b.z = d
g.y = f
j.q = m
j.z = f
n.y = d
assert d.y.y.y.y.y.y.y.txt == "n"