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

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

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

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

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

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

n.w = k
n.q = k
c.w = g
g.w = c
k.w = n
k.q = n
assert n.w.w.w.txt == "k"