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

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

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

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

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

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

b.v = a
b.x = h
a.z = h
h.z = a
assert a.z.z.z.txt == "h"