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

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

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

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

g = A("g")
m = B("m")
f = C("f")
k = D("k")
b = B("b")

g.z = f
g.o = f
m.q = k
f.s = g
k.r = b
b.q = k
assert b.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.o: C = None
        self.txt = txt

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

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

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

g = A("g")
m = B("m")
f = C("f")
k = D("k")
b = B("b")

g.z = f
g.o = f
m.q = k
f.s = g
k.r = b
b.q = k
assert b.q.r.q.txt == "k"