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

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

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

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

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

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

l.w = g
l.x = c
m.s = c
n.s = b
b.w = g
b.x = c
g.s = l
c.w = m
c.x = l
assert n.s.x.w.s.txt == "c"