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

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

g = A("g")
f = B("f")
m = B("m")
n = B("n")
j = A("j")
l = A("l")

g.u = j
g.y = l
f.x = g
m.x = l
n.x = g
j.u = l
j.y = l
l.u = j
l.y = g
assert f.x.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.y: A = None
        self.txt = txt

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

g = A("g")
f = B("f")
m = B("m")
n = B("n")
j = A("j")
l = A("l")

g.u = j
g.y = l
f.x = g
m.x = l
n.x = g
j.u = l
j.y = l
l.u = j
l.y = g
assert f.x.u.y.txt == "l"