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

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

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

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

a = A("a")
l = B("l")
c = C("c")
h = D("h")
g = A("g")
b = C("b")
m = A("m")
n = B("n")
f = B("f")

a.p = c
l.r = a
l.y = h
l.v = m
c.u = h
c.q = b
c.v = a
c.x = l
h.u = m
g.p = c
b.u = h
b.q = c
b.v = a
b.x = l
m.p = c
n.r = m
n.v = m
n.y = h
f.r = m
f.v = m
f.y = h
assert f.y.u.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
c = C("c")
h = D("h")
g = A("g")
b = C("b")
m = A("m")
n = B("n")
f = B("f")

a.p = c
l.r = a
l.y = h
l.v = m
c.u = h
c.q = b
c.v = a
c.x = l
h.u = m
g.p = c
b.u = h
b.q = c
b.v = a
b.x = l
m.p = c
n.r = m
n.v = m
n.y = h
f.r = m
f.v = m
f.y = h
assert f.y.u.p.v.txt == "a"