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

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

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

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

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

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

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