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

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

d = A("d")
c = B("c")
k = A("k")

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

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

d = A("d")
c = B("c")
k = A("k")

d.o = k
d.x = c
c.o = d
c.y = d
k.o = d
k.x = c
assert d.o.x.o.txt == "d"