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

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

m = A("m")
j = B("j")
l = B("l")
b = B("b")
g = A("g")
d = B("d")
e = A("e")

m.w = l
m.t = j
j.u = g
j.x = g
l.u = e
l.x = m
b.u = e
b.x = e
g.w = j
g.t = b
d.u = m
d.x = g
e.w = b
e.t = d
assert m.w.x.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.t: B = None
        self.txt = txt

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

m = A("m")
j = B("j")
l = B("l")
b = B("b")
g = A("g")
d = B("d")
e = A("e")

m.w = l
m.t = j
j.u = g
j.x = g
l.u = e
l.x = m
b.u = e
b.x = e
g.w = j
g.t = b
d.u = m
d.x = g
e.w = b
e.t = d
assert m.w.x.w.u.txt == "e"