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

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

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

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

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

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

b.u = d
b.o = g
k.p = m
k.s = f
m.u = k
m.o = g
g.u = d
g.o = j
d.p = m
d.s = k
j.u = k
j.o = g
f.p = j
f.s = k
assert d.p.u.p.o.o.txt == "j"