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

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

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

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

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

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

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

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

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

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

a.v = k
k.r = g
k.q = g
g.p = a
l.v = a
l.y = g
h.r = g
h.q = g
m.v = a
m.y = g
assert l.v.v.r.p.v.txt == "k"