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

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

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.v: D = None
        self.p: D = None
        self.txt = txt

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

n = A("n")
f = B("f")
a = C("a")
i = D("i")
h = B("h")
c = D("c")

n.p = i
n.s = a
n.q = a
f.p = h
f.u = n
a.u = i
a.p = i
a.v = c
i.p = c
i.z = c
i.q = n
i.w = n
h.p = f
h.u = n
c.p = i
c.z = i
c.q = n
c.w = n
assert c.w.q.v.q.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.s: C = None
        self.q: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.v: D = None
        self.p: D = None
        self.txt = txt

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

n = A("n")
f = B("f")
a = C("a")
i = D("i")
h = B("h")
c = D("c")

n.p = i
n.s = a
n.q = a
f.p = h
f.u = n
a.u = i
a.p = i
a.v = c
i.p = c
i.z = c
i.q = n
i.w = n
h.p = f
h.u = n
c.p = i
c.z = i
c.q = n
c.w = n
assert c.w.q.v.q.q.p.txt == "i"