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

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

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

j = A("j")
i = B("i")
h = C("h")
l = A("l")
f = C("f")
d = C("d")
g = A("g")

j.r = d
i.y = j
h.y = i
h.w = i
h.p = j
l.r = d
f.y = i
f.w = i
f.p = l
d.y = i
d.w = i
d.p = g
g.r = f
assert h.p.r.y.y.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

j = A("j")
i = B("i")
h = C("h")
l = A("l")
f = C("f")
d = C("d")
g = A("g")

j.r = d
i.y = j
h.y = i
h.w = i
h.p = j
l.r = d
f.y = i
f.w = i
f.p = l
d.y = i
d.w = i
d.p = g
g.r = f
assert h.p.r.y.y.r.p.r.txt == "f"