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

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

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

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

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

d.p = j
d.r = j
m.y = j
j.s = d
j.u = h
g.x = j
g.v = d
g.u = m
h.x = j
h.v = d
h.u = m
assert g.v.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.r: C = None
        self.txt = txt

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

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

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

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

d.p = j
d.r = j
m.y = j
j.s = d
j.u = h
g.x = j
g.v = d
g.u = m
h.x = j
h.v = d
h.u = m
assert g.v.r.s.txt == "d"