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

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

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

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

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

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

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

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

k.r = c
n.y = g
n.q = m
i.p = g
c.r = k
g.p = i
m.r = c
f.y = g
f.q = m
assert c.r.r.r.r.txt == "c"