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

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

g = A("g")
m = B("m")
n = A("n")
h = B("h")
k = B("k")

g.w = h
m.x = g
m.u = g
n.w = h
h.x = n
h.u = n
k.x = g
k.u = n
assert n.w.x.w.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

g = A("g")
m = B("m")
n = A("n")
h = B("h")
k = B("k")

g.w = h
m.x = g
m.u = g
n.w = h
h.x = n
h.u = n
k.x = g
k.u = n
assert n.w.x.w.u.w.txt == "h"