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

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

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

i = A("i")
k = B("k")
l = C("l")
a = C("a")
m = A("m")

i.t = m
k.q = l
l.x = k
l.q = k
a.x = k
a.q = k
m.t = i
assert a.x.q.x.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
l = C("l")
a = C("a")
m = A("m")

i.t = m
k.q = l
l.x = k
l.q = k
a.x = k
a.q = k
m.t = i
assert a.x.q.x.q.q.txt == "k"