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

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

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

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

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

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

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

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

i.r = g
g.r = c
e.p = d
k.r = c
c.r = k
a.p = d
d.p = e
assert d.p.p.p.p.txt == "d"