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

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

g = A("g")
j = B("j")
k = B("k")

g.w = j
g.r = k
j.w = k
j.s = g
k.w = j
k.s = g
assert g.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: B = None
        self.txt = txt

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

g = A("g")
j = B("j")
k = B("k")

g.w = j
g.r = k
j.w = k
j.s = g
k.w = j
k.s = g
assert g.w.w.w.txt == "j"