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

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

g = A("g")
b = B("b")
l = A("l")

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

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

g = A("g")
b = B("b")
l = A("l")

g.p = b
g.x = b
b.w = g
l.p = b
l.x = b
assert b.w.x.w.txt == "g"