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

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

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

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

c = A("c")
e = B("e")
j = C("j")
n = D("n")
h = A("h")
g = B("g")
m = A("m")

c.p = j
c.s = h
e.w = g
e.s = j
e.r = j
j.w = g
j.z = n
n.o = e
n.s = h
h.p = j
h.s = m
g.w = e
g.s = j
g.r = j
m.p = j
m.s = h
assert j.z.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.s: A = None
        self.txt = txt

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

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

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

c = A("c")
e = B("e")
j = C("j")
n = D("n")
h = A("h")
g = B("g")
m = A("m")

c.p = j
c.s = h
e.w = g
e.s = j
e.r = j
j.w = g
j.z = n
n.o = e
n.s = h
h.p = j
h.s = m
g.w = e
g.s = j
g.r = j
m.p = j
m.s = h
assert j.z.s.p.txt == "j"