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

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

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

f = A("f")
d = B("d")
j = C("j")
i = A("i")

f.t = i
f.q = i
d.u = j
j.q = f
i.t = f
i.q = f
assert f.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.q: A = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
j = C("j")
i = A("i")

f.t = i
f.q = i
d.u = j
j.q = f
i.t = f
i.q = f
assert f.q.t.q.txt == "i"