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

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

i = A("i")
d = B("d")
n = B("n")
h = A("h")
m = B("m")
l = A("l")
c = A("c")

i.p = c
d.o = i
d.q = i
n.o = c
n.q = l
h.p = c
m.o = i
m.q = i
l.p = c
c.p = h
assert d.o.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

i = A("i")
d = B("d")
n = B("n")
h = A("h")
m = B("m")
l = A("l")
c = A("c")

i.p = c
d.o = i
d.q = i
n.o = c
n.q = l
h.p = c
m.o = i
m.q = i
l.p = c
c.p = h
assert d.o.p.p.txt == "h"