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

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

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

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

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

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

b.p = g
b.w = f
f.q = g
f.x = g
g.p = b
g.w = f
assert b.p.p.w.txt == "f"