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

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

n = A("n")
l = B("l")
h = A("h")
m = B("m")
j = B("j")
i = B("i")
d = A("d")

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

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

n = A("n")
l = B("l")
h = A("h")
m = B("m")
j = B("j")
i = B("i")
d = A("d")

n.x = l
n.w = h
l.s = h
h.x = m
h.w = n
m.s = n
j.s = n
i.s = d
d.x = i
d.w = n
assert j.s.w.w.x.txt == "l"