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

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

l = A("l")
g = B("g")
e = A("e")
f = A("f")
c = B("c")
n = B("n")
h = A("h")
k = A("k")

l.o = e
g.u = e
e.o = f
f.o = l
c.u = f
n.u = k
h.o = e
k.o = l
assert g.u.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
e = A("e")
f = A("f")
c = B("c")
n = B("n")
h = A("h")
k = A("k")

l.o = e
g.u = e
e.o = f
f.o = l
c.u = f
n.u = k
h.o = e
k.o = l
assert g.u.o.o.o.o.txt == "f"