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

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: A = None
        self.txt = txt

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

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

g = A("g")
e = B("e")
h = C("h")
l = D("l")
m = D("m")

g.q = l
g.v = l
g.y = h
e.t = m
e.w = g
h.y = e
l.v = h
m.v = h
assert l.v.y.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.y: C = None
        self.v: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: D = None
        self.w: A = None
        self.txt = txt

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

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

g = A("g")
e = B("e")
h = C("h")
l = D("l")
m = D("m")

g.q = l
g.v = l
g.y = h
e.t = m
e.w = g
h.y = e
l.v = h
m.v = h
assert l.v.y.w.q.txt == "l"