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

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

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

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

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

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

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