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

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

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

f = A("f")
n = B("n")
g = C("g")
a = B("a")
d = B("d")
h = A("h")
i = C("i")

f.v = h
f.s = d
n.t = d
g.r = i
a.t = d
d.t = a
h.v = f
h.s = n
i.r = g
assert g.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.s: B = None
        self.txt = txt

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

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

f = A("f")
n = B("n")
g = C("g")
a = B("a")
d = B("d")
h = A("h")
i = C("i")

f.v = h
f.s = d
n.t = d
g.r = i
a.t = d
d.t = a
h.v = f
h.s = n
i.r = g
assert g.r.r.r.r.r.r.txt == "g"