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

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

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

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

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

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

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

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

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

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

b.u = g
n.p = g
n.v = c
c.t = b
c.r = b
c.s = g
g.v = b
g.y = b
assert n.p.y.u.y.txt == "b"