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

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

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

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

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

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

c.w = b
c.s = b
b.t = c
b.q = g
g.w = b
g.s = b
assert g.s.q.w.txt == "b"