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

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

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

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

b = A("b")
i = B("i")
k = C("k")
m = D("m")
n = A("n")

b.o = m
b.v = m
i.q = k
i.y = n
k.x = i
m.r = n
n.o = m
n.v = m
assert b.v.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: D = None
        self.v: D = None
        self.txt = txt

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

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

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

b = A("b")
i = B("i")
k = C("k")
m = D("m")
n = A("n")

b.o = m
b.v = m
i.q = k
i.y = n
k.x = i
m.r = n
n.o = m
n.v = m
assert b.v.r.v.r.txt == "n"