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

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

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

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

f = A("f")
l = B("l")
j = C("j")
a = D("a")
e = C("e")

f.p = e
l.x = a
l.z = a
l.p = f
l.t = e
j.u = e
j.v = e
a.w = f
a.t = f
a.p = f
a.r = l
e.u = j
e.v = j
assert f.p.u.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
j = C("j")
a = D("a")
e = C("e")

f.p = e
l.x = a
l.z = a
l.p = f
l.t = e
j.u = e
j.v = e
a.w = f
a.t = f
a.p = f
a.r = l
e.u = j
e.v = j
assert f.p.u.v.u.txt == "j"