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

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

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

d = A("d")
c = B("c")
g = C("g")
e = A("e")
a = A("a")
f = B("f")
n = C("n")

d.r = e
c.r = d
c.p = e
g.z = n
e.r = d
a.r = e
f.r = a
f.p = d
n.z = g
assert a.r.r.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.r: A = None
        self.p: A = None
        self.txt = txt

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

d = A("d")
c = B("c")
g = C("g")
e = A("e")
a = A("a")
f = B("f")
n = C("n")

d.r = e
c.r = d
c.p = e
g.z = n
e.r = d
a.r = e
f.r = a
f.p = d
n.z = g
assert a.r.r.r.r.r.r.txt == "d"