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

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

b = A("b")
a = B("a")
c = A("c")
k = B("k")

b.w = c
a.p = k
a.v = b
c.w = b
k.p = a
k.v = c
assert a.p.v.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

b = A("b")
a = B("a")
c = A("c")
k = B("k")

b.w = c
a.p = k
a.v = b
c.w = b
k.p = a
k.v = c
assert a.p.v.w.w.txt == "c"