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

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

n = A("n")
e = B("e")
b = B("b")
h = A("h")
j = B("j")
a = A("a")
f = A("f")

n.q = h
e.z = a
b.z = n
h.q = n
j.z = a
a.q = h
f.q = h
assert b.z.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

n = A("n")
e = B("e")
b = B("b")
h = A("h")
j = B("j")
a = A("a")
f = A("f")

n.q = h
e.z = a
b.z = n
h.q = n
j.z = a
a.q = h
f.q = h
assert b.z.q.q.q.q.q.q.txt == "n"