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

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

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

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

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

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

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