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

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

g = A("g")
a = B("a")
f = B("f")
e = A("e")
d = B("d")

g.u = e
g.o = d
a.y = e
f.y = g
e.u = g
e.o = a
d.y = g
assert e.o.y.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.o: B = None
        self.txt = txt

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

g = A("g")
a = B("a")
f = B("f")
e = A("e")
d = B("d")

g.u = e
g.o = d
a.y = e
f.y = g
e.u = g
e.o = a
d.y = g
assert e.o.y.u.u.u.txt == "g"