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

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

i = A("i")
c = B("c")
g = A("g")

i.p = c
c.w = g
g.p = c
assert i.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

i = A("i")
c = B("c")
g = A("g")

i.p = c
c.w = g
g.p = c
assert i.p.w.p.txt == "c"