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

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

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

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

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

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

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

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

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

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

h.y = a
a.r = h
l.q = f
l.p = f
l.t = h
l.u = h
f.o = h
f.p = a
f.y = a
g.q = f
g.p = f
g.t = h
g.u = h
assert a.r.y.r.y.r.txt == "h"