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

class B:
    def __init__(self, txt: str):
        self.q: D = 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.x: B = None
        self.txt = txt

l = A("l")
b = B("b")
k = C("k")
f = D("f")
a = B("a")
e = A("e")

l.q = f
l.z = e
b.q = f
k.v = e
f.x = a
a.q = f
e.q = f
e.z = l
assert e.q.x.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.z: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: D = 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.x: B = None
        self.txt = txt

l = A("l")
b = B("b")
k = C("k")
f = D("f")
a = B("a")
e = A("e")

l.q = f
l.z = e
b.q = f
k.v = e
f.x = a
a.q = f
e.q = f
e.z = l
assert e.q.x.q.x.q.txt == "f"