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

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

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

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

f = A("f")
a = B("a")
e = C("e")
d = D("d")
g = D("g")
n = C("n")
c = A("c")
j = B("j")
k = C("k")
i = D("i")

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

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

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

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

f = A("f")
a = B("a")
e = C("e")
d = D("d")
g = D("g")
n = C("n")
c = A("c")
j = B("j")
k = C("k")
i = D("i")

f.u = k
a.q = j
a.p = j
a.r = e
e.q = d
d.r = a
d.v = i
g.r = j
g.v = i
n.q = g
c.u = n
j.q = a
j.p = a
j.r = n
k.q = d
i.r = a
i.v = d
assert e.q.r.q.r.q.r.p.txt == "a"