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

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

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

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

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

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

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