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

d = A("d")
l = B("l")
a = A("a")
h = A("h")
c = A("c")
n = B("n")
e = A("e")
j = A("j")
g = A("g")

d.w = n
d.x = c
l.s = h
a.w = l
a.x = d
h.w = n
h.x = a
c.w = n
c.x = j
n.s = c
e.w = n
e.x = j
j.w = l
j.x = h
g.w = n
g.x = j
assert c.w.s.x.w.s.w.s.w.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

d = A("d")
l = B("l")
a = A("a")
h = A("h")
c = A("c")
n = B("n")
e = A("e")
j = A("j")
g = A("g")

d.w = n
d.x = c
l.s = h
a.w = l
a.x = d
h.w = n
h.x = a
c.w = n
c.x = j
n.s = c
e.w = n
e.x = j
j.w = l
j.x = h
g.w = n
g.x = j
assert c.w.s.x.w.s.w.s.w.txt == "n"