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

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

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

g.v = h
h.x = g
h.y = g
h.q = a
h.o = k
k.p = g
f.y = k
f.u = h
a.v = h
assert g.v.o.p.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

g.v = h
h.x = g
h.y = g
h.q = a
h.o = k
k.p = g
f.y = k
f.u = h
a.v = h
assert g.v.o.p.v.q.txt == "a"