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

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

c = A("c")
a = B("a")
j = B("j")
i = A("i")
b = A("b")
k = A("k")
h = A("h")

c.p = i
c.o = j
a.u = c
a.y = h
j.u = i
j.y = c
i.p = k
i.o = j
b.p = c
b.o = j
k.p = b
k.o = j
h.p = c
h.o = j
assert j.u.o.u.p.o.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: B = None
        self.txt = txt

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

c = A("c")
a = B("a")
j = B("j")
i = A("i")
b = A("b")
k = A("k")
h = A("h")

c.p = i
c.o = j
a.u = c
a.y = h
j.u = i
j.y = c
i.p = k
i.o = j
b.p = c
b.o = j
k.p = b
k.o = j
h.p = c
h.o = j
assert j.u.o.u.p.o.u.p.txt == "k"