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

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

g = A("g")
d = B("d")
l = B("l")
f = B("f")
k = A("k")
n = A("n")

g.r = k
g.u = l
d.o = n
l.o = n
f.o = k
k.r = g
k.u = f
n.r = k
n.u = f
assert f.o.r.r.r.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
l = B("l")
f = B("f")
k = A("k")
n = A("n")

g.r = k
g.u = l
d.o = n
l.o = n
f.o = k
k.r = g
k.u = f
n.r = k
n.u = f
assert f.o.r.r.r.u.o.txt == "n"