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

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

h = A("h")
f = B("f")
n = B("n")

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

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

h = A("h")
f = B("f")
n = B("n")

h.v = f
f.z = n
n.z = f
assert h.v.z.z.txt == "f"