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

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

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

f = A("f")
l = B("l")
n = C("n")
i = B("i")

f.r = i
f.t = i
l.x = n
n.q = l
n.y = f
n.t = f
i.x = n
assert i.x.q.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.t: B = None
        self.txt = txt

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

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

f = A("f")
l = B("l")
n = C("n")
i = B("i")

f.r = i
f.t = i
l.x = n
n.q = l
n.y = f
n.t = f
i.x = n
assert i.x.q.x.t.txt == "f"