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

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

m = A("m")
n = B("n")
f = B("f")
d = B("d")
b = B("b")
i = B("i")
l = A("l")
a = B("a")
c = A("c")

m.w = a
m.y = c
n.x = m
f.x = m
d.x = l
b.x = m
i.x = c
l.w = a
l.y = m
a.x = l
c.w = d
c.y = m
assert d.x.w.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.y: A = None
        self.txt = txt

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

m = A("m")
n = B("n")
f = B("f")
d = B("d")
b = B("b")
i = B("i")
l = A("l")
a = B("a")
c = A("c")

m.w = a
m.y = c
n.x = m
f.x = m
d.x = l
b.x = m
i.x = c
l.w = a
l.y = m
a.x = l
c.w = d
c.y = m
assert d.x.w.x.y.txt == "m"