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

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

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

a = A("a")
k = B("k")
l = C("l")
h = C("h")

a.q = k
a.t = l
k.r = h
k.t = a
k.y = l
l.q = k
l.p = k
l.r = k
h.q = k
h.p = k
h.r = k
assert a.q.t.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.txt = txt

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

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

a = A("a")
k = B("k")
l = C("l")
h = C("h")

a.q = k
a.t = l
k.r = h
k.t = a
k.y = l
l.q = k
l.p = k
l.r = k
h.q = k
h.p = k
h.r = k
assert a.q.t.t.q.txt == "k"