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

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

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

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

l = A("l")
g = B("g")
n = C("n")
b = D("b")
e = D("e")
j = B("j")

l.t = n
g.y = l
n.y = j
n.r = j
b.x = n
b.o = j
e.x = n
e.o = g
j.y = l
assert e.x.y.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
n = C("n")
b = D("b")
e = D("e")
j = B("j")

l.t = n
g.y = l
n.y = j
n.r = j
b.x = n
b.o = j
e.x = n
e.o = g
j.y = l
assert e.x.y.y.t.txt == "n"