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

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

b = A("b")
a = B("a")
h = B("h")
e = A("e")

b.z = e
a.o = h
a.v = b
h.o = a
h.v = b
e.z = b
assert a.o.v.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
h = B("h")
e = A("e")

b.z = e
a.o = h
a.v = b
h.o = a
h.v = b
e.z = b
assert a.o.v.z.z.txt == "b"