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

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

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

i = A("i")
k = B("k")
a = C("a")
n = B("n")
d = A("d")

i.q = d
k.y = n
a.y = n
n.y = k
d.q = i
assert d.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

i = A("i")
k = B("k")
a = C("a")
n = B("n")
d = A("d")

i.q = d
k.y = n
a.y = n
n.y = k
d.q = i
assert d.q.q.q.q.q.txt == "i"