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.p: B = None
        self.r: A = None
        self.txt = txt

g = A("g")
f = B("f")
c = A("c")
b = B("b")
h = A("h")
m = A("m")

g.u = m
g.o = f
f.p = b
f.r = g
c.u = m
c.o = f
b.p = f
b.r = m
h.u = g
h.o = f
m.u = g
m.o = b
assert g.o.p.p.r.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.p: B = None
        self.r: A = None
        self.txt = txt

g = A("g")
f = B("f")
c = A("c")
b = B("b")
h = A("h")
m = A("m")

g.u = m
g.o = f
f.p = b
f.r = g
c.u = m
c.o = f
b.p = f
b.r = m
h.u = g
h.o = f
m.u = g
m.o = b
assert g.o.p.p.r.u.txt == "m"