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

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

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

class D:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.s: D = None
        self.txt = txt

j = A("j")
l = B("l")
m = C("m")
d = D("d")
b = D("b")
e = A("e")
g = D("g")
a = A("a")

j.p = a
j.y = m
l.s = e
m.p = l
d.t = l
d.w = l
d.s = b
b.t = l
b.w = l
b.s = d
e.p = j
e.y = m
g.t = l
g.w = l
g.s = d
a.p = e
a.y = m
assert d.s.w.s.y.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.t: B = None
        self.w: B = None
        self.s: D = None
        self.txt = txt

j = A("j")
l = B("l")
m = C("m")
d = D("d")
b = D("b")
e = A("e")
g = D("g")
a = A("a")

j.p = a
j.y = m
l.s = e
m.p = l
d.t = l
d.w = l
d.s = b
b.t = l
b.w = l
b.s = d
e.p = j
e.y = m
g.t = l
g.w = l
g.s = d
a.p = e
a.y = m
assert d.s.w.s.y.p.s.txt == "e"