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

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

d = A("d")
n = B("n")
i = B("i")
b = A("b")
j = A("j")
e = B("e")
h = A("h")

d.o = i
d.x = b
n.o = e
i.o = n
b.o = n
b.x = d
j.o = n
j.x = b
e.o = n
h.o = i
h.x = d
assert b.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.x: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
i = B("i")
b = A("b")
j = A("j")
e = B("e")
h = A("h")

d.o = i
d.x = b
n.o = e
i.o = n
b.o = n
b.x = d
j.o = n
j.x = b
e.o = n
h.o = i
h.x = d
assert b.x.x.x.txt == "d"