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

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

h = A("h")
e = B("e")
c = A("c")
d = A("d")
g = B("g")
i = B("i")
n = B("n")
f = B("f")

h.x = c
h.q = i
e.p = g
e.o = n
c.x = h
c.q = i
d.x = c
d.q = f
g.p = f
g.o = f
i.p = f
i.o = e
n.p = e
n.o = i
f.p = i
f.o = g
assert g.p.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: B = None
        self.txt = txt

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

h = A("h")
e = B("e")
c = A("c")
d = A("d")
g = B("g")
i = B("i")
n = B("n")
f = B("f")

h.x = c
h.q = i
e.p = g
e.o = n
c.x = h
c.q = i
d.x = c
d.q = f
g.p = f
g.o = f
i.p = f
i.o = e
n.p = e
n.o = i
f.p = i
f.o = g
assert g.p.p.o.txt == "e"