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

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

g = A("g")
n = B("n")
j = A("j")
d = A("d")
k = B("k")
h = A("h")
a = A("a")

g.u = h
g.w = j
n.z = a
j.u = h
j.w = a
d.u = g
d.w = g
k.z = a
h.u = d
h.w = a
a.u = g
a.w = h
assert j.u.u.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.w: A = None
        self.txt = txt

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

g = A("g")
n = B("n")
j = A("j")
d = A("d")
k = B("k")
h = A("h")
a = A("a")

g.u = h
g.w = j
n.z = a
j.u = h
j.w = a
d.u = g
d.w = g
k.z = a
h.u = d
h.w = a
a.u = g
a.w = h
assert j.u.u.u.w.txt == "j"