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

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

f = A("f")
k = B("k")
c = A("c")

f.q = c
k.x = c
k.t = f
c.q = f
assert c.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.x: A = None
        self.t: A = None
        self.txt = txt

f = A("f")
k = B("k")
c = A("c")

f.q = c
k.x = c
k.t = f
c.q = f
assert c.q.q.q.txt == "f"