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

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

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

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

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

g.v = m
m.x = k
m.s = k
m.q = h
k.o = h
k.v = h
k.p = m
h.p = j
j.x = k
j.s = k
j.q = h
assert m.q.p.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

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

g.v = m
m.x = k
m.s = k
m.q = h
k.o = h
k.v = h
k.p = m
h.p = j
j.x = k
j.s = k
j.q = h
assert m.q.p.s.p.s.txt == "k"