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

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

d = A("d")
c = B("c")
m = A("m")
h = A("h")

d.v = c
c.z = m
m.v = c
h.v = c
assert d.v.z.v.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: A = None
        self.txt = txt

d = A("d")
c = B("c")
m = A("m")
h = A("h")

d.v = c
c.z = m
m.v = c
h.v = c
assert d.v.z.v.z.txt == "m"