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

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

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

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

f = A("f")
b = B("b")
l = C("l")
k = D("k")
j = C("j")

f.z = j
f.r = b
b.r = k
b.u = k
l.y = b
k.q = f
k.p = l
j.y = b
assert l.y.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.r: B = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
l = C("l")
k = D("k")
j = C("j")

f.z = j
f.r = b
b.r = k
b.u = k
l.y = b
k.q = f
k.p = l
j.y = b
assert l.y.u.p.txt == "l"