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

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

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

g = A("g")
e = B("e")
i = C("i")
d = A("d")
f = A("f")
m = C("m")
j = C("j")
n = B("n")

g.q = d
e.y = d
e.q = m
e.o = m
i.u = n
i.y = d
d.q = f
f.q = g
m.u = e
m.y = g
j.u = n
j.y = d
n.y = g
n.q = m
n.o = m
assert n.y.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

g = A("g")
e = B("e")
i = C("i")
d = A("d")
f = A("f")
m = C("m")
j = C("j")
n = B("n")

g.q = d
e.y = d
e.q = m
e.o = m
i.u = n
i.y = d
d.q = f
f.q = g
m.u = e
m.y = g
j.u = n
j.y = d
n.y = g
n.q = m
n.o = m
assert n.y.q.q.q.q.txt == "d"