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

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

k = A("k")
d = B("d")
h = B("h")
f = B("f")
g = B("g")
a = A("a")
j = A("j")
m = B("m")

k.o = f
k.r = j
d.u = f
d.p = h
h.u = f
h.p = d
f.u = h
f.p = d
g.u = f
g.p = h
a.o = f
a.r = j
j.o = g
j.r = a
m.u = g
m.p = g
assert d.u.p.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
d = B("d")
h = B("h")
f = B("f")
g = B("g")
a = A("a")
j = A("j")
m = B("m")

k.o = f
k.r = j
d.u = f
d.p = h
h.u = f
h.p = d
f.u = h
f.p = d
g.u = f
g.p = h
a.o = f
a.r = j
j.o = g
j.r = a
m.u = g
m.p = g
assert d.u.p.p.u.txt == "f"