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

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

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

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

f = A("f")
n = B("n")
a = C("a")
h = D("h")
b = B("b")
c = D("c")

f.r = h
f.o = a
n.p = b
n.o = b
a.u = f
h.r = a
h.t = f
h.y = f
h.z = c
b.p = n
b.o = n
c.r = a
c.t = f
c.y = f
c.z = h
assert c.r.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.o: C = None
        self.txt = txt

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

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

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

f = A("f")
n = B("n")
a = C("a")
h = D("h")
b = B("b")
c = D("c")

f.r = h
f.o = a
n.p = b
n.o = b
a.u = f
h.r = a
h.t = f
h.y = f
h.z = c
b.p = n
b.o = n
c.r = a
c.t = f
c.y = f
c.z = h
assert c.r.u.o.txt == "a"