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

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

e = A("e")
n = B("n")
c = A("c")
g = A("g")
i = A("i")
j = B("j")
a = A("a")

e.u = j
e.w = n
n.q = j
c.u = n
c.w = n
g.u = n
g.w = j
i.u = j
i.w = n
j.q = n
a.u = n
a.w = n
assert g.w.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.w: B = None
        self.txt = txt

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

e = A("e")
n = B("n")
c = A("c")
g = A("g")
i = A("i")
j = B("j")
a = A("a")

e.u = j
e.w = n
n.q = j
c.u = n
c.w = n
g.u = n
g.w = j
i.u = j
i.w = n
j.q = n
a.u = n
a.w = n
assert g.w.q.q.q.txt == "n"