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

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

g = A("g")
c = B("c")
b = B("b")

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

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

g = A("g")
c = B("c")
b = B("b")

g.r = c
g.w = b
c.z = b
c.q = g
b.z = c
b.q = g
assert c.q.r.q.txt == "g"