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

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

class C:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

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

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

class C:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

g.u = b
g.p = d
b.v = n
b.p = n
b.y = c
b.q = d
c.s = g
d.w = n
n.u = b
n.p = d
assert b.p.u.v.p.txt == "d"