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

class B:
    def __init__(self, txt: str):
        self.t: D = 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.p: B = None
        self.v: C = None
        self.x: B = None
        self.r: C = None
        self.txt = txt

l = A("l")
g = B("g")
c = C("c")
b = D("b")

l.s = b
l.o = g
g.t = b
c.u = l
b.p = g
b.x = g
b.v = c
b.r = c
assert c.u.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.o: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: D = 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.p: B = None
        self.v: C = None
        self.x: B = None
        self.r: C = None
        self.txt = txt

l = A("l")
g = B("g")
c = C("c")
b = D("b")

l.s = b
l.o = g
g.t = b
c.u = l
b.p = g
b.x = g
b.v = c
b.r = c
assert c.u.o.t.txt == "b"