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

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

g = A("g")
b = B("b")
c = B("c")
m = B("m")

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

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

g = A("g")
b = B("b")
c = B("c")
m = B("m")

g.w = b
b.p = m
c.p = m
m.p = c
assert g.w.p.p.p.txt == "m"