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

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

h = A("h")
j = B("j")
m = B("m")

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

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

h = A("h")
j = B("j")
m = B("m")

h.z = j
j.v = m
j.t = h
m.v = j
m.t = h
assert h.z.v.v.txt == "j"