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

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

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

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

h = A("h")
k = B("k")
n = C("n")
d = D("d")
a = C("a")
c = A("c")

h.o = c
h.p = a
h.r = d
k.w = d
k.y = c
n.v = k
n.u = a
d.q = k
a.v = k
a.u = n
c.o = h
c.p = n
c.r = d
assert a.v.w.q.y.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.p: C = None
        self.r: D = None
        self.txt = txt

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

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

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

h = A("h")
k = B("k")
n = C("n")
d = D("d")
a = C("a")
c = A("c")

h.o = c
h.p = a
h.r = d
k.w = d
k.y = c
n.v = k
n.u = a
d.q = k
a.v = k
a.u = n
c.o = h
c.p = n
c.r = d
assert a.v.w.q.y.p.v.txt == "k"