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

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

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

k = A("k")
h = B("h")
g = C("g")
n = C("n")

k.t = h
k.q = h
k.v = h
h.r = n
g.p = k
n.p = k
assert h.r.p.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.v: B = None
        self.txt = txt

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

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

k = A("k")
h = B("h")
g = C("g")
n = C("n")

k.t = h
k.q = h
k.v = h
h.r = n
g.p = k
n.p = k
assert h.r.p.t.r.txt == "n"