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

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

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

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

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

i.r = a
g.t = a
g.q = m
h.q = e
b.s = i
b.u = e
b.q = e
b.p = h
d.r = i
m.s = i
m.u = n
m.q = n
m.p = h
e.t = a
e.q = b
n.t = a
n.q = m
a.r = i
assert d.r.r.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

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

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

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

i.r = a
g.t = a
g.q = m
h.q = e
b.s = i
b.u = e
b.q = e
b.p = h
d.r = i
m.s = i
m.u = n
m.q = n
m.p = h
e.t = a
e.q = b
n.t = a
n.q = m
a.r = i
assert d.r.r.r.r.r.r.r.r.r.txt == "i"