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

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

n = A("n")
d = B("d")
i = B("i")
h = B("h")
c = B("c")
g = A("g")

n.w = g
d.q = g
i.q = n
h.q = n
c.q = g
g.w = n
assert c.q.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.q: A = None
        self.txt = txt

n = A("n")
d = B("d")
i = B("i")
h = B("h")
c = B("c")
g = A("g")

n.w = g
d.q = g
i.q = n
h.q = n
c.q = g
g.w = n
assert c.q.w.w.w.txt == "n"