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

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

l = A("l")
j = B("j")
h = B("h")
c = A("c")

l.x = c
j.p = l
j.v = h
h.p = c
h.v = j
c.x = l
assert h.v.p.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

l = A("l")
j = B("j")
h = B("h")
c = A("c")

l.x = c
j.p = l
j.v = h
h.p = c
h.v = j
c.x = l
assert h.v.p.x.x.txt == "l"