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

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

g = A("g")
j = B("j")
l = A("l")
f = A("f")
d = A("d")
k = B("k")
i = B("i")
c = B("c")
a = B("a")
m = A("m")

g.s = c
g.y = f
j.p = d
l.s = j
l.y = d
f.s = j
f.y = l
d.s = j
d.y = g
k.p = m
i.p = m
c.p = m
a.p = m
m.s = i
m.y = f
assert j.p.s.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: A = None
        self.txt = txt

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

g = A("g")
j = B("j")
l = A("l")
f = A("f")
d = A("d")
k = B("k")
i = B("i")
c = B("c")
a = B("a")
m = A("m")

g.s = c
g.y = f
j.p = d
l.s = j
l.y = d
f.s = j
f.y = l
d.s = j
d.y = g
k.p = m
i.p = m
c.p = m
a.p = m
m.s = i
m.y = f
assert j.p.s.p.s.p.txt == "d"