class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.r: D = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
m = C("m")
k = D("k")
b = B("b")
d = B("d")
c = C("c")
e = A("e")
g = C("g")
j = A("j")

h.y = j
h.r = k
a.z = e
a.p = h
a.r = b
m.q = a
m.p = k
m.s = g
k.s = d
k.z = h
b.z = h
b.p = h
b.r = d
d.z = h
d.p = j
d.r = a
c.q = b
c.p = k
c.s = m
e.y = j
e.r = k
g.q = b
g.p = k
g.s = c
j.y = h
j.r = k
assert e.y.r.s.r.r.r.r.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.r: D = None
        self.txt = txt

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

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

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

h = A("h")
a = B("a")
m = C("m")
k = D("k")
b = B("b")
d = B("d")
c = C("c")
e = A("e")
g = C("g")
j = A("j")

h.y = j
h.r = k
a.z = e
a.p = h
a.r = b
m.q = a
m.p = k
m.s = g
k.s = d
k.z = h
b.z = h
b.p = h
b.r = d
d.z = h
d.p = j
d.r = a
c.q = b
c.p = k
c.s = m
e.y = j
e.r = k
g.q = b
g.p = k
g.s = c
j.y = h
j.r = k
assert e.y.r.s.r.r.r.r.p.y.txt == "j"