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

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

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

f = A("f")
k = B("k")
n = C("n")
h = A("h")
d = C("d")
e = C("e")
j = C("j")

f.s = h
k.v = h
n.r = f
h.s = f
d.r = h
e.r = f
j.r = f
assert e.r.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

f = A("f")
k = B("k")
n = C("n")
h = A("h")
d = C("d")
e = C("e")
j = C("j")

f.s = h
k.v = h
n.r = f
h.s = f
d.r = h
e.r = f
j.r = f
assert e.r.s.s.s.s.txt == "f"