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

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

m = A("m")
a = B("a")
e = B("e")
c = B("c")
f = A("f")
j = B("j")

m.p = f
a.o = j
a.u = m
e.o = j
e.u = f
c.o = j
c.u = f
f.p = m
j.o = e
j.u = f
assert a.u.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
e = B("e")
c = B("c")
f = A("f")
j = B("j")

m.p = f
a.o = j
a.u = m
e.o = j
e.u = f
c.o = j
c.u = f
f.p = m
j.o = e
j.u = f
assert a.u.p.p.txt == "m"