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

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

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

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

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

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

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

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

h.v = k
i.x = f
i.q = f
i.t = f
j.r = k
j.v = k
e.r = k
e.v = k
f.x = i
f.q = i
f.t = i
k.v = h
assert j.r.v.v.v.v.v.txt == "h"