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

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

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

g = A("g")
k = B("k")
m = C("m")
c = C("c")
i = A("i")
e = B("e")

g.r = k
g.o = k
k.p = e
m.t = g
m.s = c
m.r = k
c.t = g
c.s = m
c.r = k
i.r = k
i.o = e
e.p = k
assert e.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.o: B = None
        self.txt = txt

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

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

g = A("g")
k = B("k")
m = C("m")
c = C("c")
i = A("i")
e = B("e")

g.r = k
g.o = k
k.p = e
m.t = g
m.s = c
m.r = k
c.t = g
c.s = m
c.r = k
i.r = k
i.o = e
e.p = k
assert e.p.p.p.p.p.txt == "k"