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

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

a = A("a")
m = B("m")
c = A("c")

a.q = c
m.t = a
m.y = a
c.q = a
assert m.y.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.t: A = None
        self.y: A = None
        self.txt = txt

a = A("a")
m = B("m")
c = A("c")

a.q = c
m.t = a
m.y = a
c.q = a
assert m.y.q.q.txt == "a"