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

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

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

g = A("g")
m = B("m")
d = C("d")
k = A("k")
j = B("j")
l = A("l")
b = A("b")
i = C("i")
n = A("n")

g.r = i
g.y = k
m.y = j
m.s = j
d.p = i
k.r = d
k.y = l
j.y = m
j.s = m
l.r = i
l.y = n
b.r = i
b.y = n
i.p = d
n.r = i
n.y = l
assert n.r.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.y: A = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
d = C("d")
k = A("k")
j = B("j")
l = A("l")
b = A("b")
i = C("i")
n = A("n")

g.r = i
g.y = k
m.y = j
m.s = j
d.p = i
k.r = d
k.y = l
j.y = m
j.s = m
l.r = i
l.y = n
b.r = i
b.y = n
i.p = d
n.r = i
n.y = l
assert n.r.p.p.p.p.txt == "i"