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

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

g = A("g")
f = B("f")
i = A("i")
n = A("n")
k = B("k")
j = B("j")

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

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

g = A("g")
f = B("f")
i = A("i")
n = A("n")
k = B("k")
j = B("j")

g.u = f
f.w = i
i.u = f
n.u = j
k.w = g
j.w = g
assert j.w.u.w.txt == "i"