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

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

j = A("j")
b = B("b")
h = A("h")
d = B("d")
e = B("e")
i = B("i")
l = B("l")
a = B("a")

j.z = h
j.x = b
b.z = e
b.o = j
h.z = j
h.x = d
d.z = b
d.o = j
e.z = l
e.o = j
i.z = l
i.o = j
l.z = e
l.o = j
a.z = d
a.o = j
assert b.z.o.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: B = None
        self.txt = txt

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

j = A("j")
b = B("b")
h = A("h")
d = B("d")
e = B("e")
i = B("i")
l = B("l")
a = B("a")

j.z = h
j.x = b
b.z = e
b.o = j
h.z = j
h.x = d
d.z = b
d.o = j
e.z = l
e.o = j
i.z = l
i.o = j
l.z = e
l.o = j
a.z = d
a.o = j
assert b.z.o.z.z.txt == "j"