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

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

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

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

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

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

g.w = n
j.y = g
n.y = g
assert g.w.y.w.txt == "n"