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

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

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

g = A("g")
f = B("f")
b = C("b")
l = A("l")
h = C("h")
m = C("m")

g.o = h
g.r = h
g.u = m
f.p = b
b.r = f
b.o = f
l.o = h
l.r = h
l.u = m
h.r = f
h.o = f
m.r = f
m.o = f
assert f.p.o.p.o.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.u: C = None
        self.r: C = None
        self.txt = txt

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

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

g = A("g")
f = B("f")
b = C("b")
l = A("l")
h = C("h")
m = C("m")

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