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

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

h = A("h")
g = B("g")
e = B("e")
f = B("f")

h.w = g
g.q = h
g.w = h
e.q = h
e.w = h
f.q = h
f.w = h
assert h.w.q.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

h = A("h")
g = B("g")
e = B("e")
f = B("f")

h.w = g
g.q = h
g.w = h
e.q = h
e.w = h
f.q = h
f.w = h
assert h.w.q.w.q.txt == "h"