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

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

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

i = A("i")
m = B("m")
c = C("c")
g = A("g")
l = C("l")
n = C("n")
h = C("h")

i.p = g
i.r = g
m.y = g
c.o = n
c.u = m
c.q = g
g.p = i
g.r = i
l.o = c
l.u = m
l.q = i
n.o = h
n.u = m
n.q = i
h.o = n
h.u = m
h.q = g
assert c.q.r.r.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.txt = txt

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

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

i = A("i")
m = B("m")
c = C("c")
g = A("g")
l = C("l")
n = C("n")
h = C("h")

i.p = g
i.r = g
m.y = g
c.o = n
c.u = m
c.q = g
g.p = i
g.r = i
l.o = c
l.u = m
l.q = i
n.o = h
n.u = m
n.q = i
h.o = n
h.u = m
h.q = g
assert c.q.r.r.p.p.txt == "g"