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

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

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

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

h.r = f
h.v = f
h.t = j
f.r = j
l.q = f
l.r = f
l.z = j
j.r = i
j.t = h
j.v = f
i.r = j
assert j.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.t: A = None
        self.v: B = None
        self.txt = txt

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

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

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

h.r = f
h.v = f
h.t = j
f.r = j
l.q = f
l.r = f
l.z = j
j.r = i
j.t = h
j.v = f
i.r = j
assert j.t.t.t.t.txt == "j"