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

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

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

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

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

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

m.x = c
m.s = l
b.w = l
h.x = n
h.s = m
n.w = l
l.x = b
l.s = m
f.w = l
d.x = c
d.s = m
c.w = h
assert h.s.s.s.txt == "m"