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

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

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

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

g = A("g")
j = B("j")
i = C("i")
h = D("h")
b = D("b")
m = D("m")
n = C("n")
a = D("a")
d = B("d")

g.q = a
j.u = d
j.q = i
j.o = i
j.p = a
i.p = n
h.v = n
b.v = i
m.v = i
n.p = i
a.v = i
d.u = j
d.q = i
d.o = i
d.p = a
assert n.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

g = A("g")
j = B("j")
i = C("i")
h = D("h")
b = D("b")
m = D("m")
n = C("n")
a = D("a")
d = B("d")

g.q = a
j.u = d
j.q = i
j.o = i
j.p = a
i.p = n
h.v = n
b.v = i
m.v = i
n.p = i
a.v = i
d.u = j
d.q = i
d.o = i
d.p = a
assert n.p.p.p.p.p.p.txt == "n"