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

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

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

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

l = A("l")
a = B("a")
k = C("k")
d = D("d")
e = D("e")
g = B("g")

l.p = g
a.p = e
a.q = k
a.r = l
a.y = d
k.u = e
d.z = a
d.v = a
e.z = a
e.v = g
g.p = d
g.q = k
g.r = l
g.y = e
assert e.z.p.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

l = A("l")
a = B("a")
k = C("k")
d = D("d")
e = D("e")
g = B("g")

l.p = g
a.p = e
a.q = k
a.r = l
a.y = d
k.u = e
d.z = a
d.v = a
e.z = a
e.v = g
g.p = d
g.q = k
g.r = l
g.y = e
assert e.z.p.v.r.txt == "l"