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

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

d = A("d")
e = B("e")
n = B("n")
j = A("j")
b = B("b")
k = A("k")
h = A("h")
c = B("c")
f = B("f")

d.o = k
e.p = b
e.s = c
n.p = c
n.s = b
j.o = h
b.p = e
b.s = e
k.o = d
h.o = k
c.p = n
c.s = n
f.p = b
f.s = e
assert k.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

d = A("d")
e = B("e")
n = B("n")
j = A("j")
b = B("b")
k = A("k")
h = A("h")
c = B("c")
f = B("f")

d.o = k
e.p = b
e.s = c
n.p = c
n.s = b
j.o = h
b.p = e
b.s = e
k.o = d
h.o = k
c.p = n
c.s = n
f.p = b
f.s = e
assert k.o.o.o.txt == "d"