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

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

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

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

c = A("c")
d = B("d")
a = C("a")
h = D("h")

c.u = d
c.p = a
d.r = c
d.w = a
d.p = a
d.y = a
a.q = h
a.w = h
a.r = c
h.x = d
h.u = c
h.r = a
assert c.p.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: C = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
a = C("a")
h = D("h")

c.u = d
c.p = a
d.r = c
d.w = a
d.p = a
d.y = a
a.q = h
a.w = h
a.r = c
h.x = d
h.u = c
h.r = a
assert c.p.r.p.txt == "a"