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

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

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

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

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

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

j.v = i
j.z = h
i.p = h
h.v = i
h.z = j
assert i.p.z.v.txt == "i"