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

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

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

n = A("n")
c = B("c")
d = C("d")
e = C("e")
g = C("g")
a = B("a")
h = C("h")
j = A("j")

n.r = a
n.s = j
n.p = j
c.p = g
c.z = a
c.x = a
d.z = n
d.w = n
d.q = h
e.z = n
e.w = j
e.q = g
g.z = j
g.w = j
g.q = h
a.p = g
a.z = c
a.x = c
h.z = n
h.w = j
h.q = e
j.r = c
j.s = n
j.p = n
assert n.r.x.z.p.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.s: A = None
        self.p: A = None
        self.txt = txt

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

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

n = A("n")
c = B("c")
d = C("d")
e = C("e")
g = C("g")
a = B("a")
h = C("h")
j = A("j")

n.r = a
n.s = j
n.p = j
c.p = g
c.z = a
c.x = a
d.z = n
d.w = n
d.q = h
e.z = n
e.w = j
e.q = g
g.z = j
g.w = j
g.q = h
a.p = g
a.z = c
a.x = c
h.z = n
h.w = j
h.q = e
j.r = c
j.s = n
j.p = n
assert n.r.x.z.p.q.w.txt == "j"