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

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

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

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

n = A("n")
g = B("g")
j = C("j")
h = D("h")

n.y = g
n.q = g
n.p = h
g.q = h
j.v = g
j.q = g
h.y = j
h.v = g
h.p = g
assert h.y.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: D = None
        self.q: B = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
j = C("j")
h = D("h")

n.y = g
n.q = g
n.p = h
g.q = h
j.v = g
j.q = g
h.y = j
h.v = g
h.p = g
assert h.y.q.q.txt == "h"