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

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

g = A("g")
a = B("a")
l = B("l")

g.w = a
a.r = l
a.q = g
l.r = a
l.q = g
assert g.w.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g = A("g")
a = B("a")
l = B("l")

g.w = a
a.r = l
a.q = g
l.r = a
l.q = g
assert g.w.r.q.txt == "g"