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

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

g = A("g")
k = B("k")
f = A("f")
n = B("n")
l = A("l")
b = A("b")
a = B("a")
i = B("i")

g.u = a
k.x = g
k.u = a
f.u = n
n.x = g
n.u = k
l.u = k
b.u = a
a.x = g
a.u = n
i.x = b
i.u = k
assert f.u.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
k = B("k")
f = A("f")
n = B("n")
l = A("l")
b = A("b")
a = B("a")
i = B("i")

g.u = a
k.x = g
k.u = a
f.u = n
n.x = g
n.u = k
l.u = k
b.u = a
a.x = g
a.u = n
i.x = b
i.u = k
assert f.u.x.u.x.txt == "g"