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

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

e = A("e")
a = B("a")
j = B("j")
b = B("b")
h = A("h")
c = B("c")

e.x = h
a.o = j
j.o = c
b.o = j
h.x = e
c.o = b
assert b.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

e = A("e")
a = B("a")
j = B("j")
b = B("b")
h = A("h")
c = B("c")

e.x = h
a.o = j
j.o = c
b.o = j
h.x = e
c.o = b
assert b.o.o.o.o.txt == "j"