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

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

f = A("f")
n = B("n")
i = B("i")
k = A("k")

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

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

f = A("f")
n = B("n")
i = B("i")
k = A("k")

f.r = k
n.q = i
n.t = f
i.q = n
i.t = k
k.r = f
assert i.q.t.r.r.txt == "f"