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

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

h = A("h")
j = B("j")
f = A("f")
a = A("a")
e = A("e")
d = B("d")

h.o = f
h.y = j
j.y = a
f.o = e
f.y = j
a.o = f
a.y = j
e.o = a
e.y = d
d.y = f
assert a.y.y.y.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.y: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
f = A("f")
a = A("a")
e = A("e")
d = B("d")

h.o = f
h.y = j
j.y = a
f.o = e
f.y = j
a.o = f
a.y = j
e.o = a
e.y = d
d.y = f
assert a.y.y.y.y.o.y.txt == "j"