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

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

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

n = A("n")
h = B("h")
a = C("a")
g = B("g")
i = A("i")
d = C("d")
b = B("b")
c = C("c")

n.o = i
n.y = d
h.y = d
a.q = c
a.y = d
a.p = d
g.y = a
i.o = n
i.y = c
d.q = c
d.p = c
d.y = a
b.y = d
c.q = d
c.y = d
c.p = d
assert c.q.p.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.y: C = None
        self.txt = txt

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

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

n = A("n")
h = B("h")
a = C("a")
g = B("g")
i = A("i")
d = C("d")
b = B("b")
c = C("c")

n.o = i
n.y = d
h.y = d
a.q = c
a.y = d
a.p = d
g.y = a
i.o = n
i.y = c
d.q = c
d.p = c
d.y = a
b.y = d
c.q = d
c.y = d
c.p = d
assert c.q.p.q.q.q.q.txt == "c"