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

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

m = A("m")
a = B("a")
d = A("d")
l = A("l")
g = B("g")
n = B("n")
j = A("j")
b = B("b")
k = A("k")
c = B("c")

m.w = d
a.s = b
a.y = k
d.w = m
l.w = m
g.s = c
g.y = k
n.s = b
n.y = k
j.w = k
b.s = n
b.y = m
k.w = m
c.s = n
c.y = m
assert g.y.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
d = A("d")
l = A("l")
g = B("g")
n = B("n")
j = A("j")
b = B("b")
k = A("k")
c = B("c")

m.w = d
a.s = b
a.y = k
d.w = m
l.w = m
g.s = c
g.y = k
n.s = b
n.y = k
j.w = k
b.s = n
b.y = m
k.w = m
c.s = n
c.y = m
assert g.y.w.w.w.w.txt == "d"