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

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

a = A("a")
n = B("n")
d = B("d")
b = A("b")
g = A("g")
e = A("e")
h = B("h")

a.y = g
a.o = e
n.p = d
n.q = e
d.p = n
d.q = b
b.y = g
b.o = e
g.y = e
g.o = b
e.y = g
e.o = a
h.p = d
h.q = a
assert b.o.o.y.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: A = None
        self.txt = txt

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

a = A("a")
n = B("n")
d = B("d")
b = A("b")
g = A("g")
e = A("e")
h = B("h")

a.y = g
a.o = e
n.p = d
n.q = e
d.p = n
d.q = b
b.y = g
b.o = e
g.y = e
g.o = b
e.y = g
e.o = a
h.p = d
h.q = a
assert b.o.o.y.o.o.txt == "e"