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

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

j = A("j")
d = B("d")
c = A("c")
b = B("b")

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

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

j = A("j")
d = B("d")
c = A("c")
b = B("b")

j.o = c
j.x = c
d.y = b
c.o = j
c.x = j
b.y = d
assert b.y.y.y.y.txt == "b"