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

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

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

e = A("e")
k = B("k")
d = C("d")
g = C("g")
c = A("c")

e.s = g
k.q = e
k.p = e
k.r = g
d.s = k
g.s = k
c.s = d
assert k.r.s.p.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

e = A("e")
k = B("k")
d = C("d")
g = C("g")
c = A("c")

e.s = g
k.q = e
k.p = e
k.r = g
d.s = k
g.s = k
c.s = d
assert k.r.s.p.s.s.txt == "k"