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

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.p: A = None
        self.y: C = 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.s: B = None
        self.o: C = None
        self.q: A = None
        self.t: A = None
        self.txt = txt

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

l.p = h
l.v = h
h.u = m
h.p = l
h.y = g
g.v = l
m.s = h
m.o = g
m.q = l
m.t = l
assert h.u.o.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.p: A = None
        self.y: C = 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.s: B = None
        self.o: C = None
        self.q: A = None
        self.t: A = None
        self.txt = txt

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

l.p = h
l.v = h
h.u = m
h.p = l
h.y = g
g.v = l
m.s = h
m.o = g
m.q = l
m.t = l
assert h.u.o.v.v.txt == "h"