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

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

h = A("h")
n = B("n")
l = B("l")
b = A("b")
d = A("d")
a = B("a")

h.z = a
n.q = a
n.u = h
l.q = a
l.u = h
b.z = a
d.z = a
a.q = n
a.u = h
assert h.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

h = A("h")
n = B("n")
l = B("l")
b = A("b")
d = A("d")
a = B("a")

h.z = a
n.q = a
n.u = h
l.q = a
l.u = h
b.z = a
d.z = a
a.q = n
a.u = h
assert h.z.u.z.txt == "a"