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

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

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

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

a = A("a")
f = B("f")
l = C("l")
h = D("h")
c = D("c")
i = B("i")

a.y = i
a.q = f
f.p = a
f.r = c
l.p = i
l.x = f
l.u = h
h.y = a
h.x = a
h.o = f
c.y = a
c.x = a
c.o = f
i.p = a
i.r = h
assert f.p.q.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

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

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

a = A("a")
f = B("f")
l = C("l")
h = D("h")
c = D("c")
i = B("i")

a.y = i
a.q = f
f.p = a
f.r = c
l.p = i
l.x = f
l.u = h
h.y = a
h.x = a
h.o = f
c.y = a
c.x = a
c.o = f
i.p = a
i.r = h
assert f.p.q.r.x.txt == "a"