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

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

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

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

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

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

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

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

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

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

c.p = d
c.q = g
c.w = g
c.v = n
d.p = n
n.p = g
g.y = d
g.v = d
g.r = c
h.y = d
h.v = d
h.r = c
assert n.p.v.p.p.txt == "g"