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

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

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

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

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

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

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

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

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

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

f.p = c
f.u = c
f.q = e
i.v = f
i.p = h
k.u = h
k.x = i
k.v = f
a.w = f
e.u = n
e.x = i
e.v = f
c.u = a
c.x = i
c.v = f
n.w = f
h.w = f
assert c.u.w.q.x.p.w.u.x.txt == "i"