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

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

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

h = A("h")
j = B("j")
d = C("d")
g = A("g")

h.r = g
j.s = g
d.t = j
d.s = j
d.z = j
g.r = h
assert h.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.s: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
d = C("d")
g = A("g")

h.r = g
j.s = g
d.t = j
d.s = j
d.z = j
g.r = h
assert h.r.r.r.r.txt == "h"