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

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

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

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

l = A("l")
f = B("f")
n = C("n")
d = D("d")

l.z = d
l.o = n
l.p = n
f.y = n
f.q = l
n.v = l
d.z = l
assert f.y.v.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: D = None
        self.o: C = None
        self.p: C = None
        self.txt = txt

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

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

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

l = A("l")
f = B("f")
n = C("n")
d = D("d")

l.z = d
l.o = n
l.p = n
f.y = n
f.q = l
n.v = l
d.z = l
assert f.y.v.z.txt == "d"