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

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

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

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

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

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

i.u = n
i.w = g
e.y = g
e.u = g
j.u = i
j.w = g
n.u = i
n.w = e
g.y = e
g.u = e
assert i.u.w.y.u.txt == "e"